Skip to content

Commit e5d47ee

Browse files
Add files via upload
1 parent 163ad4d commit e5d47ee

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

Count and Say/Count_and_Say.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# 40ms 90.52%
2+
class Solution:
3+
def countAndSay(self, n):
4+
"""
5+
:type n: int
6+
:rtype: str
7+
"""
8+
def count(strs):
9+
res = ''
10+
index = 0
11+
len_strs = len(strs)
12+
13+
while index < len_strs:
14+
num = 1
15+
letter = strs[index]
16+
17+
while index < len_strs:
18+
index += 1
19+
if index >= len_strs:
20+
res += (str(num) + letter)
21+
break
22+
23+
if strs[index] == letter:
24+
num += 1
25+
else:
26+
res += (str(num) + letter)
27+
break
28+
return res
29+
30+
for i in range(n):
31+
if i is 0:
32+
temp = '1'
33+
else:
34+
temp = count(temp)
35+
return temp

0 commit comments

Comments
 (0)