Skip to content

Instantly share code, notes, and snippets.

@goish135
Created July 25, 2021 06:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goish135/65a4c33ae86cd20ff7c3adfaa52bbad8 to your computer and use it in GitHub Desktop.
Save goish135/65a4c33ae86cd20ff7c3adfaa52bbad8 to your computer and use it in GitHub Desktop.
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