1 line Python


  • 0
    D
     def reverseWords(self,s):
            return ' '.join(i for i in s.split(' ')[::-1] if i != '')
           
      Runtime 64ms
    
    def reverseWords(self,s):
            s=s.strip()
            s=s.split(' ')[::-1]
            s=' '.join(i for i in s if i != '')
            return s
    
    Runtime  40ms  
    Beats 93.20% python submission

Log in to reply
 

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