[LeetCode][Python3] 38. Count and Say
2018. 9. 21. 00:20 |
프로그래밍/LeetCode
Problem :
https://leetcode.com/problems/count-and-say/description/
My Solution :
class Solution:
def countAndSay(self, n):
"""
:type n: int
:rtype: str
"""
before = [1]
for _ in range(1, n):
result = []
count = 1
for i in range(1, len(before)):
if before[i] == before[i-1]:
count += 1
else:
result.extend([count, before[i-1]])
count = 1
result.extend([count, before[-1]])
before = result
return ''.join(map(str, before))
'프로그래밍 > LeetCode' 카테고리의 다른 글
[LeetCode][Python3] 70. Climbing Stairs (0) | 2018.09.26 |
---|---|
[LeetCode][Python3] 3. Longest Substring Without Repeating Characters (0) | 2018.09.24 |
[LeetCode][Python3] 2. Add Two Numbers (0) | 2018.09.24 |
[LeetCode][Python3] 53. Maximum Subarray (0) | 2018.09.21 |
[LeetCode][Python3] 665. Non-decreasing Array (0) | 2018.09.13 |
[LeetCode][Python3] 705. Design HashSet (0) | 2018.09.12 |
[LeetCode][Python3] 706. Design HashMap (0) | 2018.09.12 |
[LeetCode][Python3] 35. Search Insert Position (0) | 2018.09.12 |
최근에 달린 댓글 최근에 달린 댓글