48 ms Python solution in seven lines


  • 2
    J
    def longestCommonPrefix(self, strs):
        a = zip(*strs)
        pre = []
        for tup in a:
            if len(set(tup)) !=1:
                break
            pre.append(tup[0])
        return "".join(pre)

Log in to reply
 

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