思路:

求逆格雷码。

实现:

 1 class Solution
 2 {
 3 public:
 4     int minimumOneBitOperations(int n)
 5     {
 6         int res = 0;
 7         while (n)
 8         {
 9             res ^= n;
10             n >>= 1;
11         }
12         return res;
13     }
14 };

相关文章:

  • 2023-03-11
  • 2022-12-23
  • 2021-09-17
  • 2022-12-23
  • 2022-12-23
  • 2021-07-06
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-19
  • 2021-05-31
  • 2021-10-10
相关资源
相似解决方案