Skip to content

Commit 9ae992a

Browse files
committed
[LeetCode Sync] Runtime - 4 ms (61.09%), Memory - 17.9 MB (40.45%)
1 parent 16fe71e commit 9ae992a

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<p>Given two integers <code>left</code> and <code>right</code> that represent the range <code>[left, right]</code>, return <em>the bitwise AND of all numbers in this range, inclusive</em>.</p>
2+
3+
<p>&nbsp;</p>
4+
<p><strong class="example">Example 1:</strong></p>
5+
6+
<pre>
7+
<strong>Input:</strong> left = 5, right = 7
8+
<strong>Output:</strong> 4
9+
</pre>
10+
11+
<p><strong class="example">Example 2:</strong></p>
12+
13+
<pre>
14+
<strong>Input:</strong> left = 0, right = 0
15+
<strong>Output:</strong> 0
16+
</pre>
17+
18+
<p><strong class="example">Example 3:</strong></p>
19+
20+
<pre>
21+
<strong>Input:</strong> left = 1, right = 2147483647
22+
<strong>Output:</strong> 0
23+
</pre>
24+
25+
<p>&nbsp;</p>
26+
<p><strong>Constraints:</strong></p>
27+
28+
<ul>
29+
<li><code>0 &lt;= left &lt;= right &lt;= 2<sup>31</sup> - 1</code></li>
30+
</ul>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Solution:
2+
def rangeBitwiseAnd(self, left: int, right: int) -> int:
3+
while left < right:
4+
right &= right - 1
5+
return right

0 commit comments

Comments
 (0)