g0101_0200.s0137_single_number_ii.Solution Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-java17 Show documentation
Show all versions of leetcode-in-java17 Show documentation
Java Solution for LeetCode algorithm problems, continually updating
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;
}
}