larscheng / algo

0 stars 0 forks source link

【Check 83】2024-05-27 - 136. 只出现一次的数字 #191

Open larscheng opened 1 month ago

larscheng commented 1 month ago

136. 只出现一次的数字

larscheng commented 1 month ago

思路

异或运算

O(n)/O(1)

代码


    public int singleNumber(int[] nums) {
        int result =0;
        for (int i = 0; i < nums.length; i++) {
            result ^= nums[i];
        }
        return result;
    }

复杂度