1. XOR
2. BinarySearch
Arrays.sort(nums);
int left = 0, right = nums.length, mid= (left + right)/2;
while(left<right){
mid = (left + right)/2;
if(nums[mid]>mid) right = mid;
else left = mid+1;
}
return left;
287. Find the Duplicate Number(1-n)
1.hash
2.BinarySearch
162. Find Peak Element
Find one local maximum with binary search.
https://discuss.leetcode.com/topic/29329/java-solution-and-explanation-using-invariants/2
没有评论:
发表评论