D1 - Longest Common Prefix
---
class Solution:
def longestCommonPrefix(self, strs: List[str]) -> str:
if not strs:
return ""
short_str = min(strs,key=len)
print(short_str)
for i, char in enumerate(short_str):
for other in strs:
if other[i] != char:
return short_str[:i]
return short_str
#print(Solution().longestCommonPrefix(['abcs','abds']))
---
class Solution:
def longestCommonPrefix(self, strs: List[str]) -> str:
if not strs:
return ""
short_str = min(strs,key=len)
print(short_str)
for i, char in enumerate(short_str):
for other in strs:
if other[i] != char:
return short_str[:i]
return short_str
#print(Solution().longestCommonPrefix(['abcs','abds']))
全部评论
相关推荐
点赞 评论 收藏
分享
05-27 15:09
苏州大学 设计 点赞 评论 收藏
分享

点赞 评论 收藏
分享