mirror of
https://github.com/devenperez/leetcode.git
synced 2026-06-15 09:57:09 +00:00
Time: 57 ms (34.64%), Space: 13.7 MB (15.83%) - LeetHub
This commit is contained in:
@@ -0,0 +1,24 @@
|
|||||||
|
class Solution(object):
|
||||||
|
def countAndSay(self, n):
|
||||||
|
"""
|
||||||
|
:type n: int
|
||||||
|
:rtype: str
|
||||||
|
"""
|
||||||
|
said = "1"
|
||||||
|
for i in range(2, n + 1):
|
||||||
|
counting = 0
|
||||||
|
countedN = 0
|
||||||
|
newSaid = ""
|
||||||
|
for a in range(len(said)):
|
||||||
|
if said[a] != counting:
|
||||||
|
if counting != 0:
|
||||||
|
newSaid += str(countedN) + str(counting)
|
||||||
|
counting = said[a]
|
||||||
|
countedN = 1
|
||||||
|
else:
|
||||||
|
countedN += 1
|
||||||
|
|
||||||
|
newSaid += str(countedN) + str(counting)
|
||||||
|
said = newSaid
|
||||||
|
|
||||||
|
return said
|
||||||
Reference in New Issue
Block a user