53. Reverse Words in a String

Given an input string, reverse the string word by word.

For example,
Given s = "the sky is blue",

return "blue is sky the".

class Solution:
    """
    @param: s: A string
    @return: A string
    """
    def reverseWords(self, s):
        return ' '.join(reversed(s.split()))

猜你喜欢

转载自blog.csdn.net/betty1121/article/details/81017594
今日推荐