---
description: '# Medium'
---

# 201. Bitwise AND of Numbers Range

{% hint style="info" %}
Key idea: find the common bits from left to right, it's the result

So compare m and n from removing most right bit until they are equal.
{% endhint %}

```python
class Solution:
    def rangeBitwiseAnd(self, m: int, n: int) -> int:
        for i in range(32):
            if m >> i == n >> i:
                res = m >> i
                return res << i
```
