131. Leetcode 191. 位1的个数 (位运算-汉明距离相关题目)
生活随笔
收集整理的这篇文章主要介绍了
131. Leetcode 191. 位1的个数 (位运算-汉明距离相关题目)
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
class Solution:def hammingWeight(self, n: int) -> int:count = 0while n != 0:n = n & (n-1)count += 1return count
总结
以上是生活随笔为你收集整理的131. Leetcode 191. 位1的个数 (位运算-汉明距离相关题目)的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 129. Leetcode 202. 快
- 下一篇: 位运算知识点