class Solution {
public int findDuplicate(int[] nums) {
int N = nums.length;
int l = 1, r = N - 1;
while (l < r) {
int mid = l + (r - l) / 2;
int s = 0;
for (int i = 0; i < N; ++i) {
if (nums[i] <= mid) ++s;
}
if (s > mid) {
r = mid;
}
else {
l = mid + 1;
}
}
return l;
}
}
leetcode 287. Find the Duplicate Number
原文:https://www.cnblogs.com/exhausttolive/p/10667896.html