LeetCode 191 题目解答:不懂这种题有啥意思,还通过率这么低这种不应该一次 A 过去吗。
- class Solution {
- public: int hammingWeight(uint32_t n) {
- int value[33] = {};
- int count = 0;
- int sum = 0;
- while (n != 0) {
- int temp = n % 2;
- value[count] = temp;
- count++;
- n = n / 2;
- }
- for (int i = 0; i < 33; i++) {
- if (value[i] == 1) sum += 1;
- }
- return sum;
- }
- };
就爱阅读 www.92to.com 网友整理上传, 为您提供最全的知识大全, 期待您的分享,转载请注明出处。
来源: