首页 > 其他 > 详细

779. K-th Symbol in Grammar

时间:2018-05-06 14:19:06      阅读:171      评论:0      收藏:0      [点我收藏+]

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);
        }
    }
};

 

779. K-th Symbol in Grammar

原文:https://www.cnblogs.com/JTechRoad/p/8997921.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!