编程语言
首页 > 编程语言> > 力扣初级算法——最长公共前缀

力扣初级算法——最长公共前缀

作者:互联网

题目描述:
在这里插入图片描述
答案:
在这里插入图片描述

class Solution:
    def longestCommonPrefix(self, strs: List[str]) -> str:
        a= len(strs)
        if not str:
            return ""
        b = strs[0]
        c=len(b)
        for i in range(c):
            for j in range(1,a):
                if i ==len(strs[j]) or b[i] != strs[j][i]:
                    return b[0:i]
        return b

c此处:if a == 0 与if not str 相同

标签:return,前缀,strs,range,len,力扣,算法,str,longestCommonPrefix
来源: https://blog.csdn.net/weixin_51512722/article/details/120383354