Python Fast Solution Beat 90%

  • 0
    class Solution(object):
        def longestCommonPrefix(self, strs):
            :type strs: List[str]
            :rtype: str
            if not strs:return ""
            cms = strs[0]
            for stre in strs:
                leng = min([len(cms),len(stre)])
                cms = cms[:leng]
                for idx in xrange(leng):
                    if cms[idx]!=stre[idx]:
                        cms = cms[:idx]
            return cms

Log in to reply

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