请问如何将以下cnt
那一行代码简写?
public int findDuplicate(int[] nums) {
int low = 1;
int high = nums.length - 1;
while (low <= high) {
int mid = (low + high) >> 1;
int cnt = IntStream.of(nums).boxed().collect(Collectors.toList()).stream().filter(x -> x <= mid).collect(Collectors.toList()).size();
if (cnt > mid) {
high = mid - 1;
} else {
low = mid + 1;
}
}
return low;
}
PS:代码是 Leetcode Find the Duplicate Number 的(一种)解法