Re: [閒聊] 每日LeetCode
位元運算不看解答真的解不出來
easy也一樣 我好爛
:(
191. Number of 1 Bits
class Solution {
public:
int hammingWeight(uint32_t n) {
int count=0;
while(n){
count+=n%2;
n=n>>1;
}
return count;
}
};
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.25.40.62 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1708052241.A.D54.html
推
02/16 10:58,
1年前
, 1F
02/16 10:58, 1F
→
02/16 10:58,
1年前
, 2F
02/16 10:58, 2F
→
02/16 11:05,
1年前
, 3F
02/16 11:05, 3F
→
02/16 11:05,
1年前
, 4F
02/16 11:05, 4F
→
02/16 11:12,
1年前
, 5F
02/16 11:12, 5F
討論串 (同標題文章)
完整討論串 (本文為第 683 之 719 篇):