|
25 | 25 | <code>11</code> is read off as <code>"two 1s"</code> or <code>21</code>.<br />
|
26 | 26 | <code>21</code> is read off as <code>"one 2</code>, then <code>one 1"</code> or <code>1211</code>.</p>
|
27 | 27 |
|
28 | | -<p>Given an integer <i>n</i> where 1 ≤ <em>n</em> ≤ 30, generate the <i>n</i><sup>th</sup> term of the count-and-say sequence.</p> |
| 28 | +<p>Given an integer <i>n</i> where 1 ≤ <em>n</em> ≤ 30, generate the <i>n</i><sup>th</sup> term of the count-and-say sequence. You can do so recursively, in other words from the previous member read off the digits, counting the number of digits in groups of the same digit.</p> |
29 | 29 |
|
30 | 30 | <p>Note: Each term of the sequence of integers will be represented as a string.</p>
|
31 | 31 |
|
|
36 | 36 | <pre>
|
37 | 37 | <b>Input:</b> 1
|
38 | 38 | <b>Output:</b> "1"
|
| 39 | +<b>Explanation:</b> This is the base case. |
39 | 40 | </pre>
|
40 | 41 |
|
41 | 42 | <p><b>Example 2:</b></p>
|
42 | 43 |
|
43 | 44 | <pre>
|
44 | 45 | <b>Input:</b> 4
|
45 | | -<b>Output:</b> "1211"</pre> |
| 46 | +<b>Output:</b> "1211" |
| 47 | +<b>Explanation:</b> For n = 3 the term was "21" in which we have two groups "2" and "1", "2" can be read as "12" which means frequency = 1 and value = 2, the same way "1" is read as "11", so the answer is the concatenation of "12" and "11" which is "1211". |
| 48 | +</pre> |
46 | 49 |
|
47 | 50 | ### Related Topics
|
48 | 51 | [[String](../../tag/string/README.md)]
|
|
0 commit comments