精華區beta Marginalman 關於我們 聯絡資訊
位元運算不看解答真的解不出來 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
JIWP: 大師 02/16 10:58
JIWP: 為什麼不用&1 理論上比較快 02/16 10:58
ILoveElsa: %三小 02/16 11:05
wu10200512: 真假 因為我submit看這個比較快就po這個了 02/16 11:05
ILoveElsa: 背kernighan那個 n&(n-1) 02/16 11:12