Simple python solution

  • 0
    def longestCommonPrefix(self, strs):
        :type strs: List[str]
        :rtype: str
        if not strs: return ""
        commStr = strs[0]
        for i in range(1,len(strs)):
            lenTmp = 0
            lenIMin = min(len(strs[i]),len(commStr))
            while lenTmp < lenIMin and strs[i][lenTmp] == commStr[lenTmp]:
                lenTmp += 1
            commStr = strs[i][0:lenTmp]
        return commStr

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.