7-Line Python Solution, beats 97%


  • 0
    def longestCommonPrefix(self, strs):
        if not strs: return ''
        res = []
        strs.sort()
        for c1, c2 in zip(strs[0], strs[-1]):
            if c1 != c2: break
            res.append(c1)
        return ''.join(res)
    

Log in to reply
 

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