Given an input string, reverse the string word by word.
For example,
Given s = "the sky is blue
",
return "blue is sky the
".
<pre name="code" class="python">class Solution:
# @param s, a string
# @return a string
def reverseWords(self, s):
s = s.strip().split(' ')
s = s[::-1]
result = []
lens = len(s)
for i in xrange(lens):
if s[i] != '':
result.append(s[i])
result = ' '.join(result)
return result