class Solution {
public int singleNumber(int[] nums) {
int index = 0;
Map<Integer, Integer> map = new HashMap<>();
for (int num : nums) {
map.put(num, map.getOrDefault(num, 0) + 1);
}
for (Map.Entry<Integer, Integer> integerIntegerEntry : map.entrySet()) {
if (integerIntegerEntry.getValue() == 1) {
return integerIntegerEntry.getKey();
}
}
return -1;
}
}
原文链接: https://leetcode-cn.com/problems/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-ii-lcof/