Skip to content

Commit e4f3833

Browse files
committed
Create README - LeetHub
1 parent dff6ce2 commit e4f3833

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

0038-count-and-say/README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<h2><a href="https://leetcode.com/problems/count-and-say">38. Count and Saya>h2><h3>Mediumh3><hr><p>The <strong>count-and-saystrong> sequence is a sequence of digit strings defined by the recursive formula:p>
2+
3+
<ul>
4+
  • countAndSay(1) = "1"
  • 5+
  • countAndSay(n) is the run-length encoding of countAndSay(n - 1).
  • 6+
    ul>
    7+
    8+
    <p><a href="http://en.wikipedia.org/wiki/Run-length_encoding" target="_blank">Run-length encodinga> (RLE) is a string compression method that works by replacing consecutive identical characters (repeated 2 or more times) with the concatenation of the character and the number marking the count of the characters (length of the run). For example, to compress the string <code>&quot;3322251&quot;code> we replace <code>&quot;33&quot;code> with <code>&quot;23&quot;code>, replace <code>&quot;222&quot;code> with <code>&quot;32&quot;code>, replace <code>&quot;5&quot;code> with <code>&quot;15&quot;code> and replace <code>&quot;1&quot;code> with <code>&quot;11&quot;code>. Thus the compressed string becomes <code>&quot;23321511&quot;code>.p>
    9+
    10+
    <p>Given a positive integer <code>ncode>, return <em>the em><code>n<sup>thsup>code><em> element of the <strong>count-and-saystrong> sequenceem>.p>
    11+
    12+
    <p>&nbsp;p>
    13+
    <p><strong class="example">Example 1:strong>p>
    14+
    15+
    <div class="example-block">
    16+
    <p><strong>Input:strong> <span class="example-io">n = 4span>p>
    17+
    18+
    <p><strong>Output:strong> <span class="example-io">&quot;1211&quot;span>p>
    19+
    20+
    <p><strong>Explanation:strong>p>
    21+
    22+
    <pre>
    23+
    countAndSay(1) = &quot;1&quot;
    24+
    countAndSay(2) = RLE of &quot;1&quot; = &quot;11&quot;
    25+
    countAndSay(3) = RLE of &quot;11&quot; = &quot;21&quot;
    26+
    countAndSay(4) = RLE of &quot;21&quot; = &quot;1211&quot;
    27+
    pre>
    28+
    div>
    29+
    30+
    <p><strong class="example">Example 2:strong>p>
    31+
    32+
    <div class="example-block">
    33+
    <p><strong>Input:strong> <span class="example-io">n = 1span>p>
    34+
    35+
    <p><strong>Output:strong> <span class="example-io">&quot;1&quot;span>p>
    36+
    37+
    <p><strong>Explanation:strong>p>
    38+
    39+
    <p>This is the base case.p>
    40+
    div>
    41+
    42+
    <p>&nbsp;p>
    43+
    <p><strong>Constraints:strong>p>
    44+
    45+
    <ul>
    46+
  • 1 <= n <= 30
  • 47+
    ul>
    48+
    49+
    <p>&nbsp;p>
    50+
    <strong>Follow up:strong> Could you solve it iteratively?

    0 commit comments

    Comments
     (0)