We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 085460b commit 2564135Copy full SHA for 2564135
CountandSay/CountandSay.cpp
@@ -0,0 +1,26 @@
1
+class Solution {
2
+public:
3
+ string countAndSay(int n) {
4
+ // Start typing your C/C++ solution below
5
+ // DO NOT write int main() function
6
+
7
+ string begin = "1";
8
+ for (int i = 0; i < n - 1; i++) {
9
+ string next;
10
+ int start = 0;
11
+ while (start < begin.size()) {
12
+ int end = start;
13
+ int count = 0;
14
+ while (end < begin.size() && begin[start] == begin[end]) {
15
+ end += 1;
16
+ count += 1;
17
+ }
18
+ next += char('0' + count);
19
+ next += begin[start];
20
+ start = end;
21
22
+ begin = next;
23
24
+ return begin;
25
26
+};
0 commit comments