We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 8a7e1ff + e7e1ad4 commit c199faeCopy full SHA for c199fae
38. Count and Say1
@@ -0,0 +1,36 @@
1
+class Solution {
2
+public:
3
+ string ans="";
4
+ bool found=false;
5
+ void fn(string &temp,int n){
6
+ if(found)return;
7
+ if(n==1){
8
+ ans=temp;
9
+ found=true;
10
+ return;
11
+ }
12
+
13
+ char pre=temp[0];
14
+ string s=temp;
15
+ string str="";
16
+ int cnt=1;
17
+ for(int i=1;i<temp.length();i++){
18
+ if(temp[i]==pre){
19
+ cnt++;
20
+ }else{
21
+ str+=to_string(cnt);
22
+ str+=pre;
23
+ cnt=1;
24
25
+ pre=temp[i];
26
27
28
29
+ fn(str,n-1);
30
31
+ string countAndSay(int n) {
32
+ string temp="1";
33
+ fn(temp,n);
34
+ return ans;
35
36
+};
0 commit comments