[LeetCode][Python3] 14. Longest Common Prefix
2018. 9. 11. 01:28 |
프로그래밍/LeetCode
Problem :
https://leetcode.com/problems/longest-common-prefix/description/
My Solution :
class Solution:
def longestCommonPrefix(self, strs):
"""
:type strs: List[str]
:rtype: str
"""
if not strs:
return ''
word = strs[0]
for i in range(len(word)):
for s in strs[1:]:
if i > len(s)-1 or s[i] != word[i]:
return word[:i]
return word
Comment :
너비 우선 탐색 전략. Edge Case 조심.
'프로그래밍 > LeetCode' 카테고리의 다른 글
[LeetCode][Python3] 27. Remove Element (0) | 2018.09.11 |
---|---|
[LeetCode][Python3] 26. Remove Duplicates from Sorted Array (0) | 2018.09.11 |
[LeetCode][Python3] 7. Reverse Integer (0) | 2018.09.11 |
[LeetCode][Python3] 21. Merge Two Sorted Lists (0) | 2018.09.11 |
[LeetCode][Python3] 20. Valid Parentheses (0) | 2018.09.11 |
[LeetCode][Python3] 13. Roman to Integer (0) | 2018.09.11 |
[LeetCode][Python3] 9. Palindrome Number (0) | 2018.09.10 |
[LeetCode][Python3] 1. Two Sum (0) | 2018.09.10 |
최근에 달린 댓글 최근에 달린 댓글