Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions Week1/Count and Say/Divya
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
class Solution {
public:
string countAndSay(int n) {
if(n==1)
return "1";

string temp=countAndSay(n-1); //first get the result of n-1 number


int index=1;
int len=temp.length();
char temp1=temp[0];
int count=1;
string ans="";
while(index<len)
{
if(temp[index]==temp1) //match the current index with previous
count++;
else
{ //if not equal then update the ans string
string s(1,temp1);
ans+=to_string(count)+s;
count=1;
temp1=temp[index];
}
index++;
}
string num=to_string(count);
string s1(1,temp1);
ans+=num+s1;
return ans;




}
};
1 change: 0 additions & 1 deletion Week1/Count and Say/week1.md

This file was deleted.