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 d1e8065 commit 1cf4f1cCopy full SHA for 1cf4f1c
38. Count and Say
@@ -0,0 +1,24 @@
1
+class Solution {
2
+public:
3
+ string countAndSay(int n) {
4
+ string curr = "1";
5
+ if (n == 1) return curr;
6
+ for (int i = 2; i <= n; i++) {
7
+ string next = "";
8
+ int cnt = 1;
9
+ char ele = curr[0];
10
+ for (int j = 1; j < curr.size(); j++) {
11
+ if (curr[j] == ele) {
12
+ cnt++;
13
+ } else {
14
+ next += to_string(cnt) + ele;
15
+ ele = curr[j];
16
+ cnt = 1;
17
+ }
18
19
20
+ curr = next;
21
22
+ return curr;
23
24
+};
0 commit comments