摘要: 有一系列产品,从某个开始其后都不合格,给定一个判断是否合格的函数,找出N个产品中第一个不合格的产品。 正确答案: 有一道非常类似的题目 猜数游戏:1-n之内有一个数是预选的数字,每次回告诉大还是小或者正确。返回猜中的数字。 阅读全文
posted @ 2018-02-12 17:03 Sherry_Yang 阅读(111) 评论(0) 推荐(0) 编辑
摘要: 找BST树中节点之间的最小差值。 阅读全文
posted @ 2018-02-12 16:33 Sherry_Yang 阅读(98) 评论(0) 推荐(0) 编辑
摘要: 1.结论 新版的hash_map都是unordered_map了,这里只说unordered_map和map. 运行效率:unordered_map最高,而map效率较低但提供了稳定效率和有序的序列。 占用内存:map内存占用略低,unordered_map内存占用略高,而且是线性成比例的。 什么时 阅读全文
posted @ 2018-02-12 15:16 Sherry_Yang 阅读(3343) 评论(0) 推荐(1) 编辑
摘要: 这道题给了我们一个含有重复数字的无序数组,还有一个整数k,让我们找出有多少对不重复的数对(i, j)使得i和j的差刚好为k。由于k有可能为0,而只有含有至少两个相同的数字才能形成数对,那么就是说我们需要统计数组中每个数字的个数。我们可以建立每个数字和其出现次数之间的映射,然后遍历哈希表中的数字,如果 阅读全文
posted @ 2018-02-12 14:59 Sherry_Yang 阅读(105) 评论(0) 推荐(0) 编辑
摘要: Find the largest palindrome made from the product of two n-digit numbers Since the result could be very large, you should return the largest palindrom 阅读全文
posted @ 2018-02-12 14:58 Sherry_Yang 阅读(369) 评论(0) 推荐(0) 编辑
摘要: 题目标签:Array 题目给了我们一个数组 和 k。 让我们 旋转数组 k 次。 方法一: 这里有一个很巧妙的方法: 利用数组的length - k 把数组 分为两半; reverse 左边和右边的数组; reverse 总数组。 举一个例子: 1 2 3 4 5 6 7 如果k = 3 的话, 会 阅读全文
posted @ 2018-02-12 13:40 Sherry_Yang 阅读(96) 评论(0) 推荐(0) 编辑
摘要: Given an array where elements are sorted in ascending order, convert it to a height balanced BST. For this problem, a height-balanced binary tree is d 阅读全文
posted @ 2018-02-02 23:07 Sherry_Yang 阅读(94) 评论(0) 推荐(0) 编辑
摘要: BST树求得两个节点的和是target 阅读全文
posted @ 2018-01-26 21:21 Sherry_Yang 阅读(95) 评论(0) 推荐(0) 编辑
摘要: 用队列实现栈。这个实现方法十分的简单,就是在push这一步的时候直接变成逆序。 阅读全文
posted @ 2018-01-26 19:37 Sherry_Yang 阅读(89) 评论(0) 推荐(0) 编辑
摘要: 求所有左节点的和。 阅读全文
posted @ 2018-01-25 21:35 Sherry_Yang 阅读(97) 评论(0) 推荐(0) 编辑
摘要: 找两个数组的交集(不要多想,考虑啥序列之类的,就是简单的两堆数求交集啊!!!最后去个重就好了) 阅读全文
posted @ 2018-01-25 20:11 Sherry_Yang 阅读(89) 评论(0) 推荐(0) 编辑
摘要: class Solution { public: string convertToTitle(int n) { if (n == 0) { return ""; } return convertToTitle((n - 1) / 26) + (char)((n - 1) % 26 + 'A'); } }; ... 阅读全文
posted @ 2018-01-23 11:29 Sherry_Yang 阅读(100) 评论(0) 推荐(0) 编辑
摘要: 求是否有从根到叶的路径,节点和等于某个值。 返回所有和为特定值的路径 return 阅读全文
posted @ 2018-01-22 21:17 Sherry_Yang 阅读(95) 评论(0) 推荐(0) 编辑
摘要: Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), ..., (an, bn) which makes sum of 阅读全文
posted @ 2018-01-22 20:44 Sherry_Yang 阅读(92) 评论(0) 推荐(0) 编辑
摘要: 这题必会啊!!! 第一题118. 第二题119. 阅读全文
posted @ 2018-01-22 20:18 Sherry_Yang 阅读(93) 评论(0) 推荐(0) 编辑
摘要: 删除等于n的数,并返回剩余元素个数 阅读全文
posted @ 2018-01-18 22:32 Sherry_Yang 阅读(81) 评论(0) 推荐(0) 编辑
摘要: 判断两棵二叉树是否相等 阅读全文
posted @ 2018-01-18 17:13 Sherry_Yang 阅读(114) 评论(0) 推荐(0) 编辑
摘要: 合并两个有序的list 把排序好的nums2插入nums1中,假设nums1这个vector的空间永远是够的 思路:倒序!! 阅读全文
posted @ 2018-01-18 16:13 Sherry_Yang 阅读(129) 评论(0) 推荐(0) 编辑
摘要: 因为要考虑超时问题,所以虽然简单的for循环也可以做,但是要用map等内部红黑树实现的容器。 Given an array of integers, find out whether there are two distinct indices i and j in the array such t 阅读全文
posted @ 2018-01-18 12:59 Sherry_Yang 阅读(109) 评论(0) 推荐(0) 编辑
摘要: 链表反转,一发成功~ 阅读全文
posted @ 2018-01-17 10:32 Sherry_Yang 阅读(89) 评论(0) 推荐(0) 编辑
摘要: 求二叉树的最小深度: 阅读全文
posted @ 2018-01-17 10:13 Sherry_Yang 阅读(118) 评论(0) 推荐(0) 编辑
摘要: 求二叉树的最大深度 非递归写法1(直接摘自其他博客): 非递归写法2(直接摘自其他博客): 阅读全文
posted @ 2018-01-17 09:53 Sherry_Yang 阅读(157) 评论(0) 推荐(0) 编辑
摘要: 判断二叉树是否平衡 a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1. 阅读全文
posted @ 2018-01-17 09:45 Sherry_Yang 阅读(118) 评论(0) 推荐(0) 编辑
摘要: 下面是非递归的一种写法:(可以说是很漂亮了) 阅读全文
posted @ 2018-01-17 09:26 Sherry_Yang 阅读(149) 评论(0) 推荐(0) 编辑
摘要: 2的幂次 最佳解法 如果一个数是2的次方数的话,根据上面分析,那么它的二进数必然是最高位为1,其它都为0,那么如果此时我们减1的话,则最高位会降一位,其余为0的位现在都为变为1,那么我们把两数相与,就会得到0,用这个性质也能来解题,而且只需一行代码就可以搞定,如下所示: 递归 位运算 3的幂次 题目 阅读全文
posted @ 2018-01-16 13:25 Sherry_Yang 阅读(117) 评论(0) 推荐(0) 编辑
摘要: happy number Write an algorithm to determine if a number is "happy". A happy number is a number defined by the following process: Starting with any po 阅读全文
posted @ 2018-01-16 10:29 Sherry_Yang 阅读(112) 评论(0) 推荐(0) 编辑
摘要: 所谓丑数,是指质因子只能是2,3,5中的。1认为也是丑数。 阅读全文
posted @ 2018-01-16 10:12 Sherry_Yang 阅读(112) 评论(0) 推荐(0) 编辑
摘要: class Solution { public: bool isPerfectSquare(int num) { /* //方法一:蜜汁超时…… if (num num) right = mid - 1; else left = mid + 1; } return false; ... 阅读全文
posted @ 2018-01-15 22:16 Sherry_Yang 阅读(152) 评论(0) 推荐(0) 编辑
摘要: 题目: Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical. 阅读全文
posted @ 2018-01-14 14:42 Sherry_Yang 阅读(134) 评论(0) 推荐(0) 编辑
摘要: class Solution { public: int quicksort(vector& nums, int start, int end, int k){ int i = start; int j = end; int x = nums[i]; while (ix && ik-1) //出错的地方………... 阅读全文
posted @ 2018-01-14 11:53 Sherry_Yang 阅读(104) 评论(0) 推荐(0) 编辑
摘要: ques: 判断一个链表是否回文 Could you do it in O(n) time and O(1) space? method:先将链表分为两部分,将后半部分反转,最后从前往后判断是否相等。 topic: 链表,链表反转 阅读全文
posted @ 2018-01-08 22:04 Sherry_Yang 阅读(81) 评论(0) 推荐(0) 编辑
摘要: Easy: -- 直接写,bug-free Medium: -- 与实际面试重合较多,重点刷,分专题,要多刷熟练! Hard: -- 出现的题目涉及的算法有了解 【journey】 From 2018/1/5 刷题的解题思路要清晰 2018/1/14 【12题】 链表,指针,vector 【refe 阅读全文
posted @ 2018-01-05 09:03 Sherry_Yang 阅读(99) 评论(0) 推荐(0) 编辑