1545.cpp (354B)
1 class Solution { 2 public: 3 char findKthBit(int n, int k) const { 4 int flip = 0, l = (1 << n) - 1; 5 while (k > 1) { 6 if (k == l / 2 + 1) return '1' - flip; 7 if (k > l / 2) { 8 k = l + 1 - k; 9 flip = !flip; 10 } 11 l /= 2; 12 } 13 return '0' + flip; 14 } 15 };