class Solution {
public:
int kthGrammar(int N, int K) {
return helper(N, K, false);
}
int helper(int n, int k, bool reverse) {
if (n == ) return reverse;
int total = << (n-);
int half = total >> ;
if (k <= half)
return helper(n-, k, reverse);
else
return helper(n-, k-half, !reverse);
}
}; /*
lvl1: 0
lvl2: 0 1
lvl3: 0 1 1 0
lvl4: 0 1 1 0 1 0 0 1
lvl5: 0 1 1 0 1 0 0 1 1 0 0 1 0 1 1 0
0 1 1 0 1 0 0 1 1 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0 0 1 1 0 1 0 0 1
*/

779. K-th Symbol in Grammar的更多相关文章

  1. 【LeetCode】779. K-th Symbol in Grammar 解题报告(Python)

    [LeetCode]779. K-th Symbol in Grammar 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingz ...

  2. [Swift]LeetCode779. 第K个语法符号 | K-th Symbol in Grammar

    On the first row, we write a 0. Now in every subsequent row, we look at the previous row and replace ...

  3. [LeetCode] K-th Symbol in Grammar 语法中的第K个符号

    On the first row, we write a 0. Now in every subsequent row, we look at the previous row and replace ...

  4. [leetcode-779-K-th Symbol in Grammar]

    On the first row, we write a 0. Now in every subsequent row, we look at the previous row and replace ...

  5. 【leetcode】K-th Symbol in Grammar

    题目如下: 解题思路:直接把每行的数据计算出来肯定是不行的,因为N最大是30,那个第N行长度就是2^30次方,这显然不可取.那么就只能找规律了,我采取的是倒推法.例如假如我们要求出第四行第七个元素的值 ...

  6. 符号表 symbol table 符号 地址 互推

    https://zh.wikipedia.org/wiki/符号表 https://en.wikipedia.org/wiki/Symbol_table 在计算机科学中,符号表是一种用于语言翻译器(例 ...

  7. Swift LeetCode 目录 | Catalog

    请点击页面左上角 -> Fork me on Github 或直接访问本项目Github地址:LeetCode Solution by Swift    说明:题目中含有$符号则为付费题目. 如 ...

  8. LeetCode All in One题解汇总(持续更新中...)

    突然很想刷刷题,LeetCode是一个不错的选择,忽略了输入输出,更好的突出了算法,省去了不少时间. dalao们发现了任何错误,或是代码无法通过,或是有更好的解法,或是有任何疑问和建议的话,可以在对 ...

  9. 算法与数据结构基础 - 递归(Recursion)

    递归基础 递归(Recursion)是常见常用的算法,是DFS.分治法.回溯.二叉树遍历等方法的基础,典型的应用递归的问题有求阶乘.汉诺塔.斐波那契数列等,可视化过程. 应用递归算法一般分三步,一是定 ...

随机推荐

  1. 写英文bug的经验总结

    本文链接: https://www.cnblogs.com/hchengmx/p/10800855.html 由于工作原因,开bug的时候需要由英文开,刚开的时候比较痛苦,因为有些词汇老师用的不太准确 ...

  2. jQuery核心探究

    动画animate.animate({}, { duration: 5000, progress: function (now, progressNum) {}, complete: function ...

  3. JAVA的图片文字识别技术

    从2013年的记录看,JAVA中图片文字识别技术大部分采用ORC的tesseract的软件功能,后来渐渐开放了java-api调用接口. 图片文字识别技术,还是采用训练的方法.并未从根本上解决图片与文 ...

  4. Static 用法

    1.Static关键字含意:static译文是静态的,静止的,因此使用 static 修饰符声明属于类型本身而不是属于特定对象(new创建的对象)的静态成员. 2.修饰使用范围 static 修饰符可 ...

  5. python+selenium第一个脚本

    #coding=utf-8from selenium import webdriverfrom selenium.webdriver.common.keys import Keysimport tim ...

  6. selenium并行的使用

    Selenium Grid Parallel Test(C#) Author: Mars (hnynes)Email:  hnynes@gmail.comMSN:    hnynes@gmail.co ...

  7. Movideo SaaS解决方案

    类型: 定制服务 软件包: media solution collateral 联系服务商 产品详情 解决方案 概要 Movideo为媒体客户提供的SaaS解决方案部署在位于全球数据中心的Azure云 ...

  8. ES6相关特性(let & const)

    [ecma-262/8.0]http://www.ecma-international.org/ecma-262/8.0/index.html 1.Let & const let 的三个特性: ...

  9. Multi-modal Sentence Summarization with Modality Attention and Image Filtering 论文笔记

     文章已同步更新在https://ldzhangyx.github.io/,欢迎访问评论.   五个月没写博客了,不熟悉我的人大概以为我挂了…… 总之呢这段时间还是成长了很多,在加拿大实习的两个多月来 ...

  10. Altium_Designer-原理图库如何添加低电平有效的管脚?

    在编辑元件原理图符号时,在display name选项中将要加低电平的字符后面都加上“\”即可,如图: