Skip to content

Commit a2be9dc

Browse files
committed
leetcode
1 parent 6791151 commit a2be9dc

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

SingleNumberII/single_number_ii.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package main
22

3+
/*--------------------- Bit Manipulation
4+
5+
36
func singleNumber(nums []int) int {
47
var ans int = 0
58
@@ -19,3 +22,18 @@ func singleNumber(nums []int) int {
1922
2023
return ans
2124
}
25+
26+
*/
27+
28+
func singleNumber(nums []int) int {
29+
var ones int = 0
30+
var twos int = 0
31+
32+
for i := 0; i < len(nums); i++ {
33+
var number int = nums[i]
34+
ones ^= (number & ^twos)
35+
twos ^= (number & ^ones)
36+
}
37+
38+
return ones
39+
}

0 commit comments

Comments
 (0)