Short python code


  • 0
    T
    class Solution:
        # @return a string
        def longestCommonPrefix(self, strs):
            prefix = strs[0] if strs else ''
            while True:
                if all(s.startswith(prefix) for s in strs):
                    return prefix
                prefix = prefix[:-1]

Log in to reply
 

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