首页 > 其他 > 详细

Count and Say

时间:2015-08-02 21:30:48      阅读:123      评论:0      收藏:0      [点我收藏+]
class Solution {
public:
    string countAndSay(int n) {
         string res;
         if(n<=0) return res;
         res += 1;
         for(int i=0;i<n-1;i++)
            res = s_2_s(res);
         return res;
    }
    string s_2_s(string pre){
        string aft;
        int len=0;
        if(pre=="") return pre;
        int i=0;
        char temp;
        while(pre[i]){
            len=1;
            temp=pre[i];
            i++;
            while(pre[i] && pre[i]==temp){
                i++;
                len++;
            }
            aft+=len+0;  //这里没有问题,不会出现两位长度的
            aft+=temp;
        }
        cout<<aft;
        return aft;
    }
};

 

Count and Say

原文:http://www.cnblogs.com/julie-yang/p/4696728.html

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