Sunday, August 23, 2015

Leetcode 151. Reverse Words in a String

https://leetcode.com/problems/reverse-words-in-a-string/

For Python, such string processing is quite easy.

Solution:
# T:O(n) S:O(n)
class Solution:
    # @param s, a string
    # @return a string
    def reverseWords(self, s):
        return ' '.join(reversed(s.split()))
Run Time: 48 ms

No comments:

Post a Comment