标签:
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; } };
标签:
原文地址:http://www.cnblogs.com/julie-yang/p/4696728.html