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']))
----
全部评论
相关推荐

点赞 评论 收藏
分享
04-15 15:01
南京理工大学 C++ 点赞 评论 收藏
分享

点赞 评论 收藏
分享
点赞 评论 收藏
分享