Created
July 25, 2021 06:45
-
-
Save goish135/65a4c33ae86cd20ff7c3adfaa52bbad8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def countAndSay(self, n: int) -> str: | |
if n==1: | |
return "1" | |
first = 0 | |
test = str(1) | |
for j in range(2,n+1): | |
ans = "" | |
first = 0 | |
for i in test: | |
if first==0: | |
num = i | |
count = 1 | |
first = 1 | |
pre = num | |
elif i!=pre: | |
ans+=str(count) | |
ans+=str(num) | |
#print(count," ",num) | |
num = i | |
count = 1 | |
pre = num | |
else: | |
count+=1 | |
ans+=str(count) | |
ans+=str(num) | |
#print(ans) | |
test = ans | |
return test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment