forked from shichao-an/leetcode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.py
More file actions
22 lines (20 loc) · 515 Bytes
/
solution.py
File metadata and controls
22 lines (20 loc) · 515 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
"""
Write a function to find the longest common prefix string amongst an array of
strings.
"""
class Solution(object):
def longestCommonPrefix(self, strs):
"""
:type strs: List[str]
:rtype: str
"""
if not strs:
return ""
res = strs[0]
for s in strs[1:]:
n = len(s)
for i, c in enumerate(res):
if i >= n or res[i] != s[i]:
res = res[:i]
break
return res