This is my Python solution


  • 2
    G
    def longestCommonPrefix(self, strs):
            """
            :type strs: List[str]
            :rtype: str
            """
            def commonPrefix(s1, s2):
                i = 0
                for a, b in zip(s1,s2):
                    if a != b:
                        break 
                    i += 1
                return s1[:i]
            return "" if len(strs)==0 else reduce(commonPrefix, strs)

Log in to reply
 

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