We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 1d5ec1a + 634db9d commit 34701cfCopy full SHA for 34701cf
problems/1356.根据数字二进制下1的数目排序.md
@@ -156,6 +156,17 @@ class Solution {
156
## Python
157
158
```python
159
+class Solution:
160
+ def sortByBits(self, arr: List[int]) -> List[int]:
161
+ arr.sort(key=lambda num: (self.count_bits(num), num))
162
+ return arr
163
+
164
+ def count_bits(self, num: int) -> int:
165
+ count = 0
166
+ while num:
167
+ num &= num - 1
168
+ count += 1
169
+ return count
170
```
171
172
## Go
0 commit comments