摘要: 描述:用两个栈实现一个队列。队列的声明如下,请实现它的两个函数 appendTail 和 deleteHead ,分别完成在队列尾部插入整数和在队列头部删除整数的功能。(若队列中没有元素,deleteHead 操作返回 -1 ) tags: stack 思路 声明两个栈,一个入栈,一个出栈。注意出栈 阅读全文
posted @ 2020-08-15 18:24 珊珊来迟0 阅读(52) 评论(0) 推荐(0) 编辑
摘要: 描述:输入一个链表的头节点,从尾到头反过来返回每个节点的值(用数组返回)。 tags: recursive 思路 利用栈来存储,出栈即可 class Solution: def reversePrint(self, head: ListNode) -> List[int]: res = [] whi 阅读全文
posted @ 2020-08-15 18:21 珊珊来迟0 阅读(22) 评论(0) 推荐(0) 编辑
摘要: 描述:请实现一个函数,把字符串 s 中的每个空格替换成"%20"。 tags: array 思路 python无聊解法 class Solution: def replaceSpace(self, s: str) -> str: return s.replace(' ', '%20') 阅读全文
posted @ 2020-08-15 18:17 珊珊来迟0 阅读(56) 评论(0) 推荐(0) 编辑
摘要: 描述:在一个 n * m 的二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。 tags: binary search 思路 利用数组有序的定义,使用二分查找法。从左下或右上出发,例从左下出 阅读全文
posted @ 2020-08-15 18:14 珊珊来迟0 阅读(31) 评论(0) 推荐(0) 编辑
摘要: 题目:找出数组中重复的数字。 描述:在一个长度为 n 的数组 nums 里的所有数字都在 0~n-1 的范围内。数组中某些数字是重复的,但不知道有几个数字重复了,也不知道每个数字重复了几次。请找出数组中任意一个重复的数字。 示例 1: 输入: [2, 3, 1, 0, 2, 5, 3] 输出:2 或 阅读全文
posted @ 2020-08-15 18:06 珊珊来迟0 阅读(46) 评论(0) 推荐(0) 编辑
摘要: TODO 阅读全文
posted @ 2020-08-15 15:49 珊珊来迟0 阅读(68) 评论(0) 推荐(0) 编辑
摘要: removeElement class Solution { public: int removeElement(vector<int>& nums, int val) { int k = 0; // #no equal val element count for(int i = 0; i < nu 阅读全文
posted @ 2020-08-15 15:48 珊珊来迟0 阅读(64) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution { 2 public: 3 int removeDuplicates(vector<int>& nums) { 4 if(nums.size() < 2){ 5 return nums.size(); 6 } 7 int cur = nums[0]; 8 int k 阅读全文
posted @ 2020-08-15 15:43 珊珊来迟0 阅读(94) 评论(0) 推荐(0) 编辑
摘要: solution_1: 1 class Solution { 2 public: 3 void moveZeroes(vector<int>& nums) { 4 int k = 0; // k # number of zero element 5 for(int i = 0; i < nums.s 阅读全文
posted @ 2020-08-15 15:24 珊珊来迟0 阅读(59) 评论(0) 推荐(0) 编辑