-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path38CountAndSay.py
More file actions
28 lines (28 loc) · 838 Bytes
/
Copy path38CountAndSay.py
File metadata and controls
28 lines (28 loc) · 838 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class Solution:
def countAndSay(self, n):
"""
:type n: int
:rtype: str
"""
if n==1:
return '1'
if n>1:
size=len(solution.countAndSay(n-1))
i=0
outstr=''
while i<size:
count=1
for j in range(i,size):
if i+count<size and solution.countAndSay(n-1)[i]==solution.countAndSay(n-1)[i+count]:
count=count+1
else:
outstr+=str(count)
outstr+=str(solution.countAndSay(n-1)[i])
break
i=i+count
return outstr
if __name__=='__main__':
n=1
solution=Solution()
result=solution.countAndSay(n)
print(result)