随笔分类 -  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 阅读全文
posted @ 2020-05-16 14:14 梦醒潇湘 阅读(303) 评论(0) 推荐(0)
摘要:题目: 解答: 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 阅读全文
posted @ 2020-05-16 14:00 梦醒潇湘 阅读(275) 评论(0) 推荐(0)
摘要:题目: 解答: 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 阅读全文
posted @ 2020-05-16 13:51 梦醒潇湘 阅读(305) 评论(0) 推荐(0)