287. 寻找重复数 - 力扣(LeetCode) (leetcode-cn.com)
class Solution {
public int findDuplicate(int[] nums) {
Map<Integer,Boolean> map = new HashMap<>();
for(int num:nums){
map.put(num,!map.containsKey(num));
}
for(Map.Entry<Integer,Boolean> m:map.entrySet()){
if(!m.getValue()) return m.getKey();
}
return -1;
}
}