Skip to content

Commit

Permalink
py实现
Browse files Browse the repository at this point in the history
  • Loading branch information
rinwf committed Sep 30, 2018
1 parent ecc15e2 commit 22a9f3d
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lc14. Longest Common Prefix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Solution:
def longestCommonPrefix(self, strs):
"""
:type strs: List[str]
:rtype: str
"""
if not strs:
return ''
res = ''
# length = len(strs[0])
for i in range(len(strs[0])):
for j in range(1, len(strs)):
if len(strs[j]) < i + 1:
return res
if strs[j][i] != strs[0][i]:
return res
res += strs[0][i]
return res


strs = ["flower", "flow", "flight"]
s = Solution()
print(s.longestCommonPrefix(strs))

0 comments on commit 22a9f3d

Please sign in to comment.