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".
解题方法
注意要用s.split()
, 不要pass任何参数,这样连续的whitespace都会被去掉
Solution
class Solution(object):
def reverseWords(self, s):
"""
:type s: str
:rtype: str
"""
return " ".join(map(lambda x : x[::-1], s[::-1].split()))