forked from moranzcw/LeetCode-NOTES
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.cpp
More file actions
38 lines (38 loc) · 743 Bytes
/
solution.cpp
File metadata and controls
38 lines (38 loc) · 743 Bytes
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
35
36
37
38
class Solution
{
public:
string revolution(string s)
{
string ret;
char pre =s[0];
int count = 1;
for(int i = 1; i < s.size(); i ++)
{
if(s[i]==pre)
{
count ++;
}
else
{
char tmp = count+'0';
ret = ret + tmp + pre;
pre = s[i];
count = 1;
}
}
char tmp = count+'0';
ret = ret + tmp + pre;
return ret;
}
string countAndSay(int n)
{
string ret = "1";
int j = 1;
while( j< n)
{
ret=revolution(ret);
j++;
}
return ret;
}
};