寻找重复数
class Solution {
public int findDuplicate(int[] nums) {
int len = nums.length;
int l = 1, r = len - 1;
while (l < r) {
int mid = (l + r) / 2;
int count = 0;
for (int num : nums) {
if (num <= mid) {
count++;
}
}
if (count > mid) {
r = mid;
}else {
l = mid + 1;
}
}
return l;
}
}
标签:二分,nums,int,mid,len,num
From: https://www.cnblogs.com/changebaobao/p/17387498.html