python 42 ms beat 90%


  • 0
    X
    class Solution(object):                                                             
        def longestCommonPrefix(self, strs):                                            
            """                                                                         
            :type strs: List[str]                                                       
            :rtype: str                                                              
            """                                                                      
            if len(strs) == 1:                                                                           
                return strs[0]                                                       
            result = []                                                              
            strs_rev = zip(*strs)                                                    
            for i in xrange(len(strs_rev)):                                          
                if len(set(strs_rev[i])) is not 1:                                   
                    break                                                            
                else:                                                                
                    result.append(strs_rev[i][0])                                    
            return "".join(result) 
    

Log in to reply
 

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