class Solution(object):
    def longestCommonPrefix(self, strs):
        """
        :type strs: List[str]
        :rtype: str
        """
        if len(strs) <= 0:
            return ""
        shortestLen=None
        for tmp in strs:
            if len(tmp) < shortestLen or shortestLen == None:
                shortestLen = len(tmp)
        if shortestLen <= 0:
            return ""
        if len(strs) == 1:
            return strs[0]
        bolStop=False
        res=""
        firstStr=strs[0]
        del strs[0]
        
        for index in range(shortestLen):
            strCarry=""
            for tmpStr in strs:
                strNext = tmpStr[index]
                strCur = firstStr[index]
                if strNext != strCur:
                    bolStop=True
                    break
                elif strNext == strCur:
                    strCarry=strCur
            if bolStop:
                break
            res+=strCarry
                
        return res

 

相关文章:

  • 2022-03-07
  • 2021-09-18
  • 2021-09-14
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-03-05
  • 2022-12-23
  • 2022-01-18
  • 2021-08-02
  • 2021-09-25
  • 2022-02-24
  • 2021-08-26
相关资源
相似解决方案