剑指 Offer 53 - II. 0~n-1中缺失的数字

题目链接:https://leetcode-cn.com/problems/que-shi-de-shu-zi-lcof/

执行用时:0 ms, 在所有 Java 提交中击败了100.00% 的用户
内存消耗:42.3 MB, 在所有 Java 提交中击败了5.02% 的用户

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Solution {
public int missingNumber(int[] nums) {
int left = 0, right = nums.length - 1;
while (left <= right) {
int mid = (left + right) >> 1;
if (nums[mid] == mid) {
left = mid + 1;
} else {
right = mid - 1;
}
}
return left;
}
}

剑指 Offer 53 - II. 0~n-1中缺失的数字
https://pisces34.github.io/2022/02/12/leetcode/offer53-2/
发布于
2022年2月12日
许可协议