leetcode --38. Count and Say

来源:互联网 发布:老时时彩遗漏数据 编辑:程序博客网 时间:2024/06/05 05:48

题目:https://leetcode.com/problems/count-and-say/tabs/description

代码:

class Solution {public:    string countAndSay(int n) {        string temp="1",res;        int count;        if(n==0) return "";        if(n==1) return "1";        for(int i = 1;i<n;i++){            int len = temp.size();            for(int j=0;j<len;j++){                   count = 1;                while(temp[j]==temp[j+1]&&j+1<len){                    count++;                    j++;                }               res+=to_string(count)+temp[j];            }            temp=res;            res.clear();        }        return temp;    }};

原创粉丝点击