Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- string countAndSay(int n) {
- string s = "1";
- char c;
- int count;
- while(n>1){
- string temp = "";
- count = 1;
- c = s[0];
- for(int i = 1; i< s.length(); i++){
- if(s[i]==c){
- count++;
- }
- else{
- temp += to_string(count);
- temp += c;
- count = 1;
- c = s[i];
- }
- }
- temp += to_string(count);
- temp += c;
- s = temp;
- n--;
- }
- return s;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement