Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 37865a0

Browse files
author
侯利朋
committed
.\476.number-complement ok
1 parent 1a6f005 commit 37865a0

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

476.number-complement.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* @lc app=leetcode id=476 lang=golang
3+
*
4+
* [476] Number Complement
5+
*/
6+
// 0 ms
7+
func findComplement(num int) int {
8+
bits := uint(0)
9+
for num0 := num; num0 != 0; num0 >>= 1 {
10+
bits++
11+
}
12+
return num ^ (1<<bits - 1)
13+
}

0 commit comments

Comments
 (0)