#way1:
import os
class Solution:
def longestCommonPrefix(self , strs ):
return os.path.commonprefix(strs)
#way2:
class Solution:
def longestCommonPrefix(self, strs):
if not strs:
return ''
s = strs[0]
for i in range(1,len(strs)):
while strs[i].find(s) != 0:
s = s[:-1]
return s
编写一个函数来查找字符串数组中的最长公共前缀。
最新推荐文章于 2024-01-18 16:34:14 发布