-
Notifications
You must be signed in to change notification settings - Fork 0
/
38_100
34 lines (34 loc) · 876 Bytes
/
38_100
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
c++:100%
class Solution {
public:
string countAndSay(int n) {
string s;
char c;
for (int i = 0; i < n; i++){
if (i == 0){
s = "1";
}
else{
string t;
c = s[0];
for (int j = 1, k = 1; j < s.length() + 1; j ++){
if (j == s.length())
t += to_string(k) + to_string(1);
else
{
if(c == s[j]){
k ++;
}
else{
t += to_string(k) + c;
c = s[j];
k = 1;
}
}
}
s = t;
}
}
return s;
}
};