1 line python solution

  • 0

    This solution is not in place ( strings are immutable in python anyways), it would be great if you can write one and post!

    def reverseWords(self, s):
    	return ' '.join([x for x in [x.strip(' ') for x in s.split(' ')[::-1]] if x != ''])

Log in to reply

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