Skip to content

Commit cf45ebb

Browse files
author
cpppy
authored
Create 38_Count_and_Say.cc
1 parent 4f0ea35 commit cf45ebb

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

38_Count_and_Say.cc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution {
2+
public:
3+
string countAndSay(int n) {
4+
string str;
5+
string result="1";
6+
while(n-1){
7+
str=result;
8+
result="";
9+
int count=1;
10+
for(int i=0;i<str.size();++i){
11+
if(str[i]==str[i+1]){
12+
count++;
13+
}
14+
else{
15+
result+=to_string(count)+str[i];
16+
count=1;
17+
}
18+
}
19+
n--;
20+
}
21+
return result;
22+
}
23+
};

0 commit comments

Comments
 (0)