LeetCode 14. Longest Common Pref
作者:
费城的二鹏 | 来源:发表于
2018-11-22 13:28 被阅读13次
class Solution:
def longestCommonPrefix(self, strs):
"""
:type strs: List[str]
:rtype: str
"""
if len(strs) == 0:
return ""
if len(strs) == 1:
return strs[0]
index = len(strs[0])
for i in range(1, len(strs)):
pos = -1
for j in range(len(strs[i])):
if j < len(strs[0]) and strs[0][j] == strs[i][j]:
pos = j
else:
break
index = min(index, pos + 1)
print(strs[0][0:index])
return strs[0][0:index]
本文标题:LeetCode 14. Longest Common Pref
本文链接:https://www.haomeiwen.com/subject/pcllqqtx.html
网友评论