All Downloads are FREE. Search and download functionalities are using the official Maven repository.

g0101_0200.s0137_single_number_ii.Solution Maven / Gradle / Ivy

There is a newer version: 1.24
Show newest version
package g0101_0200.s0137_single_number_ii;

// #Medium #Array #Bit_Manipulation

public class Solution {
    public int singleNumber(int[] nums) {
        int ones = 0;
        int twos = 0;
        for (int i = 0; i < nums.length; i++) {
            ones = (ones ^ nums[i]) & (~twos);
            twos = (twos ^ nums[i]) & (~ones);
        }
        return ones;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy