leetcode 191. 位1的个数(java & python3)

java:
public class Solution {
// you need to treat n as an unsigned value
public int hammingWeight(int n) {
int res = 0;
for(int i = 0; i < 32; i++){ if((n & (1 << i)) != 0){ res ++; } } return res; } } public class Solution { // you need to treat n as an unsigned value public int hammingWeight(int n) { int res = 0; while(n != 0){ res ++; n &=

leetcode 191. 位1的个数(java & python3)最先出现在Python成神之路

版权声明:
作者:ht
链接:https://www.techfm.club/p/15013.html
来源:TechFM
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>