diff --git a/leetcode/201.BitwiseANDofNumbersRange/bitwiseANDofNumbersRange.go b/leetcode/201.BitwiseANDofNumbersRange/bitwiseANDofNumbersRange.go new file mode 100644 index 0000000..9491bdd --- /dev/null +++ b/leetcode/201.BitwiseANDofNumbersRange/bitwiseANDofNumbersRange.go @@ -0,0 +1,21 @@ +// https://leetcode.com/problems/bitwise-and-of-numbers-range + +package main + +import ( + "fmt" +) + +func rangeBitwiseAnd(left int, right int) int { + for left < right { + right &= (right - 1) + } + return right +} + +func main() { + left := 1 + right := 2147483647 + + fmt.Println(rangeBitwiseAnd(left, right)) +}