3133.cpp (285B)
1 class Solution { 2 public: 3 long long minEnd(int n, long long x) const { 4 using ull = unsigned long long; 5 6 for (ull i = 1, j = n - 1; j > 0 && i > 0;) { 7 if (!(x & i)) x |= j & 1 ? i : 0, j >>= 1; 8 i <<= 1; 9 } 10 11 return x; 12 } 13 };