Leetcode 14. Longest Common Prefix(python)

class Solution(object):
    def longestCommonPrefix(self, strs):
        """
        :type strs: List[str]
        :rtype: str
        """
        if len(strs)==0:
            return ""
        result=""
    
        s_len=len(strs[0])
        for l in strs:
            s_len=min(s_len,len(l))
    
        for i in range(s_len):
            ch=strs[0][i]
            for j in range(1,len(strs)):
                if strs[j][i]!=ch:
                    return result
            result+=ch
    
        return result
            
        

  

posted @ 2016-04-05 17:17  colors  阅读(870)  评论(0编辑  收藏  举报