摘要:Note: 这道题很有意思,用的是二分法。想法是不停的试错。这个博客主把这个问题说的很清楚 https://xuezhashuati.blogspot.com/2017/03/lintcode-437-copy-books.html 其实二分法的方法可以变化的点很有限,最多变化的就是检查条件。一般难
阅读全文
摘要:Given a set of distinct positive integers, find the largest subset such that every pair (Si, Sj) of elements in this subset satisfies: Si % Sj = 0 or
阅读全文
摘要:Given a sequence of integers, find the longest increasing subsequence (LIS). You code should return the length of the LIS. Given a sequence of integer
阅读全文
摘要:方法一: 动态规划 https://segmentfault.com/a/1190000003768736 https://siddontang.gitbooks.io/leetcode-solution/content/dynamic_programming/perfect_squares.htm
阅读全文
摘要:Important Note:1) Pay attention to the number that is less than 1.0, because x^0.5 will larger than x. So we need to always set the right side to be 1
阅读全文
摘要:Important Reference: http://stackoverflow.com/questions/13093602/finding-subarray-with-maximum-sum-number-of-elements http://www.jiuzhang.com/qa/2942/
阅读全文
摘要:The reference link: http://www.code123.cc/docs/leetcode-notes/binary_search/search_a_2d_matrix_ii.html 题解 - 自右上而左下
阅读全文
摘要:This question is very hard, just remember it:Explaination: 思路清晰,就是二倍法。直接用除数去一个一个加,直到被除数被超过的话,会超时。解决办法每次将被除数增加1倍,同时将count也增加一倍,如果超过了被除数,那么用被除数减去当前和再继续本
阅读全文
摘要:Important Node: 1) This problem has two parts: a. find the closest number's to the target and return its index. This is standard binary search problem
阅读全文
摘要:The worst situation O(N). Actually we can either just loop through, or we can compare num[mid] with the num[end], if they are the same, that means it'
阅读全文
摘要:O(logN) This question turns to find the first and last element of the target in a sorted array. Just be careful with the two result coming out of the
阅读全文
摘要:O(N) if element can repeat, the worst case, you cannot throw away any section. eg. [1, 1, 1, 1, 0, 1, 1] target = 0, you cannot throw any section. We
阅读全文
摘要:O(logN) Important Point: Once the target is in one section, use the point in that section as benchmark In this problem, if the target >= startVal, use
阅读全文
摘要:O(logN) Check four different situations: 1) The peek 2) increasing section 3) decreasing section 4) minimum
阅读全文
摘要:O(logN) There are two section: 1) increase array which the first element is larger than end one. 2) the minimum to end Comparing with the endVal, 1) i
阅读全文
摘要:O(logN) Important Point: if there "mid" exists, it has at laest three elements in "nums", because otherwise it will not come inside the loop. So later
阅读全文
摘要:class Solution { /** * @param x: An integer * @return: The sqrt of x */ public int sqrt(int x) { // write your code here if (x < 0) { return -1; ...
阅读全文
摘要:If it is two eggs: http://datagenetics.com/blog/july22012/index.html Imagine we drop our first egg from floor n, if it breaks, we can step through the
阅读全文