779. K-th Symbol in Grammar

https://leetcode.com/problems/k-th-symbol-in-grammar/description/

class Solution {
public:
    int kthGrammar(int N, int K, bool rootZero = true) {
        if (N == 1)     return rootZero ? 0 : 1;
        int lastCnt = 1 << (N-2);
        if (K <= lastCnt) {
            return kthGrammar(N-1, K, rootZero);
        }
        else {
            return kthGrammar(N-1, K-lastCnt, !rootZero);
        }
    }
};
原文地址:https://www.cnblogs.com/JTechRoad/p/8997921.html