摘要:
Given a collection of numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1]... 阅读全文
摘要:
Given an unsorted integer array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm sho... 阅读全文
摘要:
Iterative ways: 1 int binarySearch (int[] a, int x) { 2 int low = 0; 3 int high = a.length - 1; 4 int mid; 5 6 while (low x) {12 ... 阅读全文
摘要:
Analysis: 这道题是二分查找Search Insert Position的变体,思路并不复杂,就是先用二分查找找到其中一个target,然后再往左右找到target的边缘。找边缘的方法跟二分查找仍然是一样的,只是相等的情况依然要往左找(找左边缘)或往右找(找右边缘)。这样下来总共进行了三次二 阅读全文