Skip to content

Commit

Permalink
Create bitwise-and-of-numbers-range.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
kamyu104 committed Sep 8, 2015
1 parent e3ba317 commit 2b9c05d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions C++/bitwise-and-of-numbers-range.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Time: O(1)
// Space: O(1)

class Solution {
public:
int rangeBitwiseAnd(int m, int n) {
while (m < n) {
n &= n-1;
}
return n;
}
};

0 comments on commit 2b9c05d

Please sign in to comment.