Leetcode string

1.Count and Say

 

class Solution {
public:
    string countAndSay(int n) 
    {
        string s1,s2="";
        s1="1";
        if(n==1)return s1;
        for(int i=1;i<n;i++)
        {
            int j=0;int k=0;
            while(j<s1.size())
            {
                char c=s1[j];
                while(s1[j]==c&&j<s1.size())
                {
                    j++;k++;                    
                }
                s2+='0'+k;
                s2+=c;
                k=0;
            }
            s1=s2;
            s2="";
        }
        return s1;
    }
};

 

 错误代码

s2+='0'+k+c;

posted @ 2013-06-13 15:37  代码改变未来  阅读(124)  评论(0编辑  收藏  举报