1 class Solution {
 2 public:
 3     int hammingWeight(uint32_t n) {
 4         int result = 0;
 5         while (n > 0) {
 6             if (n & 1) {
 7                 result++;
 8             }
 9             n >>= 1;
10         }
11         return result;
12     }
13 };

 

posted on 2015-03-21 10:04  keepshuatishuati  阅读(89)  评论(0编辑  收藏  举报