1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/第K个语法符号 [k-th-symbol-in-grammar].html
2022-03-29 12:43:11 +08:00

46 lines
1.3 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>我们构建了一个包含 <code>n</code> 行(&nbsp;<strong>索引从 1&nbsp; 开始&nbsp;</strong>)的表。首先在第一行我们写上一个 <code>0</code>。接下来的每一行,将前一行中的<code>0</code>替换为<code>01</code><code>1</code>替换为<code>10</code></p>
<ul>
<li>例如,对于 <code>n = 3</code> ,第 <code>1</code> 行是 <code>0</code> ,第 <code>2</code> 行是 <code>01</code> 第3行是 <code>0110</code></li>
</ul>
<p>给定行数&nbsp;<code>n</code>&nbsp;和序数 <code>k</code>,返回第 <code>n</code> 行中第 <code>k</code>&nbsp;个字符。(&nbsp;<code>k</code>&nbsp;<strong>从索引 1 开始</strong></p>
<p><br />
<strong>示例 1:</strong></p>
<pre>
<strong>输入:</strong> n = 1, k = 1
<strong>输出:</strong> 0
<strong>解释: </strong>第一行:<u>0</u>
</pre>
<p><strong>示例 2:</strong></p>
<pre>
<strong>输入:</strong> n = 2, k = 1
<strong>输出:</strong> 0
<strong>解释:</strong>
第一行: 0
第二行: 0<u>1</u>
</pre>
<p><strong>示例 3:</strong></p>
<pre>
<strong>输入:</strong> n = 2, k = 2
<strong>输出:</strong> 1
<strong>解释:</strong>
第一行: 0
第二行: 0<u>1</u>
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= n &lt;= 30</code></li>
<li><code>1 &lt;= k &lt;= 2<sup>n - 1</sup></code></li>
</ul>