题解 | #数组中只出现一次的两个数字#
数组中只出现一次的两个数字
http://www.nowcoder.com/practice/389fc1c3d3be4479a154f63f495abff8
import java.util.*;
public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param array int整型一维数组 * @return int整型一维数组 */ public int[] FindNumsAppearOnce (int[] array) { // write code here Set set = new HashSet<>(); for(int i = 0;i < array.length;i++){ if(set.contains(array[i])){ set.remove(array[i]); }else{ set.add(array[i]); } } int[] res = new int[2]; int i = 0; for(Integer num : set){ res[i++] = num; } return res; } }
我居南半坡 文章被收录于专栏
多刷题,积蓄力量,欢迎讨论