您的位置:首页 > 其它

找出数组中只出现一次的数字

2017-03-21 13:54 381 查看
public static void getOneTimeNum(int[] array) {

if (array == null || array.length < 1) {
return;
}

Map<Integer,Integer> map =new HashMap<Integer, Integer>();

for (int i = 0; i < array.length; i++) {

if (map.get(array[i]) == null) {
map.put(array[i], 1);
} else {
map.put(array[i], map.get(array[i]) + 1);
}

}

for (Integer key  : map.keySet()) {
if (map.get(key) == 1) {//出现一次
System.out.print(key + " ");
}
}

}


本文参考:

http://blog.csdn.net/xidianluke/article/details/38267775
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: