Given an input string, reverse the string word by word.
For example,
Given s = "the sky is blue
",
return "blue is sky the
".
语言使用python:
整体思路:使用spilit()函数把以空格区分的字符串列表分割 然后倒置列表,最后写入字符串中并且添加空格,然后去除首位空格返回
def reverseWords(s):
"""
:type s: str
:rtype: str
"""
res=[]
result=' '
a=' '
temp=s.split()
res=temp[::-1]
for i in res:
result +=i+' '
a=result[1:-1]
return a