解法:二分查找法
class Solution {
public int missingNumber(int[] nums) {
int i =0,j = nums.length-1;
while(i<=j){
int m = (i+j)/2;
if(nums[m]==m){
i = m+1;
}else{
j = m-1;
}
}
return i;
}
}
参考:
- https://leetcode-cn.com/problems/que-shi-de-shu-zi-lcof/solution/mian-shi-ti-53-ii-0n-1zhong-que-shi-de-shu-zi-er-f/
- https://blog.algomooc.com/0532.html#%E4%B8%89%E3%80%81%E5%8F%82%E8%80%83%E4%BB%A3%E7%A0%81