Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- string countAndSay(int n) {
- if( n<1) return "";
- string ans = "1";
- while(--n){
- string cur="";
- for(int i=0;i < (int)ans.size(); i++ ){
- int cnt=1;
- while(i+1<ans.size() && ans[i] == ans[i+1]){
- cnt++;
- i++;
- }
- cur += to_string(cnt) + ans[i];
- }
- ans = cur;
- }
- return ans;
- }
- };
Add Comment
Please, Sign In to add comment