import java.util.*;
public class FindOdd {
public static void main(String[] args) {
int [] arr = {1, 4, 7, 3, 1, 3, 7, 4, 6, 9, 6};
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
for(int i=0; i<arr.length; i++) {
if(map.containsKey(arr[i])) {
map.remove(arr[i]);//出现了偶数次则删掉
} else {
map.put(arr[i], 1);//还未出现过则次数设为1
}
}
Iterator iterator = map.keySet().iterator();
while(iterator.hasNext()) {
System.out.println(iterator.next());
}
}
}
Java找出数组中唯一的出现奇数次的数
最新推荐文章于 2023-04-24 22:34:34 发布