parent
77c1098ff3
commit
8451af1e78
|
|
@ -156,6 +156,17 @@ class Solution {
|
||||||
## Python
|
## Python
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
class Solution:
|
||||||
|
def sortByBits(self, arr: List[int]) -> List[int]:
|
||||||
|
arr.sort(key=lambda num: (self.count_bits(num), num))
|
||||||
|
return arr
|
||||||
|
|
||||||
|
def count_bits(self, num: int) -> int:
|
||||||
|
count = 0
|
||||||
|
while num:
|
||||||
|
num &= num - 1
|
||||||
|
count += 1
|
||||||
|
return count
|
||||||
```
|
```
|
||||||
|
|
||||||
## Go
|
## Go
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue