数组中只出现一次的数字

    技术2024-04-18  86

    题目描述: 一个整型数组里除了两个数字之外,其他的数字都出现了两次。请写程序找出这两个只出现一次的数字。

    public static void FindNumsAppearOnce(int [] array,int num1[] , int num2[]) { Stack<Integer> sta = new Stack<>(); Arrays.sort(array); for(int i = 0; i < array.length; i++){ if(sta.empty() || sta.peek() != array[i]){ sta.push(array[i]); }else if(sta.peek() == array[i]){ sta.pop(); } } num1[0] = sta.pop(); num2[0] = sta.pop(); }
    Processed: 0.008, SQL: 9