LeetCode 38.Count and Say

Posted dacc123

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LeetCode 38.Count and Say相关的知识,希望对你有一定的参考价值。

题目

c++
```
class Solution
public:
string a[31];
string countAndSay(int n)

     a[1]="1";
for(int i=2;i<=30;i++)

    char s1=a[i-1][0];int num=1;
    string str="";
    for(int j=1;j<a[i-1].size();j++)
    
        if(a[i-1][j]!=a[i-1][j-1])
        
            char x = num+'0';
            str+=x;
            str+=s1;
            
            num=1;
            s1=a[i-1][j];
            continue;
        
        else
            num++;
    
    char x = num+'0';
    str += x;
    str += s1;
    
    a[i]=str;

    
    return a[n];

;
``

以上是关于LeetCode 38.Count and Say的主要内容,如果未能解决你的问题,请参考以下文章

LeetCode 38: Count and Say

Leetcode 38: Count and Say

Leetcode38. Count and Say

[LeetCode 38] Count and Say

leetcode-38 Count And Say

LeetCode 38. Count and Say