image_2022-03-29_17-58-36.png
27 KB
#medium
#N287. Find the Duplicate Number
problem link
#solution
#N287. Find the Duplicate Number
problem link
#solution
class Solution {
public int findDuplicate(int[] nums) {
Set<Integer> set = new HashSet<>();
for(int n: nums){
if(!set.contains(n))
set.add(n);
else
return n;
}
return -1;
}
}