0779.cpp (244B)
1 class Solution { 2 public: 3 constexpr int kthGrammar(const int n, const int k) const { 4 if (n == 1) return 0; 5 const int mid = 1 << (n - 2); 6 return k > mid ? !kthGrammar(n - 1, k - mid) : kthGrammar(n - 1, k); 7 } 8 };