1.代码
class Solution:
def longestCommonPrefix(self, strs: List[str]) -> str:
length1 = len(strs)
i = 0
result = ""
min_length = min(len(s) for s in strs)
while (i<min_length):
a = strs[0][i]
flag = True
for j in range(length1):
if(strs[j][i] != a):
flag = False
break
if(flag == False):
break
result = result + a
i = i+1
return result
2.思路
从下标0开始依次比较每个字符串下标相同部分是否相等。