首页 > 其他 > 详细

【LeetCode 38】报数

时间:2019-11-13 11:12:31      阅读:71      评论:0      收藏:0      [点我收藏+]

题目链接

【题解】


模拟题

【代码】

class Solution {
public:
    string inttostr(int x){
        string temp="";
        while (x>0){
            char key = (x%10)+'0';
            temp= key+temp;
            x/=10;
        }
        return temp;
    }
    string countAndSay(int n) {
        string a = "1";
        string b = "";
        for (int i = 0;i < n-1;i++){
            int len = a.size();
            for (int j = 0;j < len;j++){
                int k = j;
                while (k+1<len && a[k+1]==a[k]) k++;
                int num = k-j+1;
                string snum = inttostr(num);
                snum=snum+a[k];
                b = b+snum;
                j= k;
            }
            a = b;
            b = "";
        }
        return a;
    }
};

【LeetCode 38】报数

原文:https://www.cnblogs.com/AWCXV/p/11847491.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!