随笔分类 - leetcode-位运算
摘要:题目: 解答: 1 class Solution { 2 public: 3 bool isPowerOfThree(int n) 4 { 5 if (n < 1) 6 { 7 return false; 8 } 9 10 while (n % 3 == 0) 11 { 12 n /= 3; 13
阅读全文
摘要:题目: 解答: 1 class Solution { 2 public: 3 int hammingWeight(uint32_t n) 4 { 5 int res = 0; 6 while(n != 0) 7 { 8 res += n & 1; 9 n >>= 1; 10 } 11 return
阅读全文
摘要:题目: 解答: 1 class Solution { 2 public: 3 uint32_t reverseBits(uint32_t n) 4 { 5 int res = 0; 6 for (int i = 0; i < 32; i++) 7 { 8 res = (res << 1) + (n
阅读全文

浙公网安备 33010602011771号