class Solution { public: string countAndSay(int n) { string str,ans; str="1"; if(n--==1) return str; while(n--){ ans.clear(); int left=0,right=0; while(right<str.size()){ if(str[right]==str[left]) right++; else{ ans+=(right-left+‘0‘); ans+=str[left]; left=right; right++; } } ans+=(right-left+‘0‘); ans+=str[left]; str=ans; } return ans; } };
原文:https://www.cnblogs.com/lettleshel/p/9017257.html