public int missingNumber(int[] nums) {
int n = nums.length;
int lo = 0, hi = nums.length-1;
while (lo <= hi) {
int mid = lo + (hi - lo) / 2;
if(nums[mid] == mid) lo = mid + 1;
else hi = mid - 1;
}
return lo;
}
public int missingNumber(int[] nums) {
int n = nums.length;
int res = n;
for (int i = 0; i < n; i++) {
res ^= i;
res ^= nums[i];
}
return res;
}
268. Missing Number
最新推荐文章于 2024-07-29 07:32:50 发布