标签:style blog io ar color sp for on div
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): arr = s.split(‘ ‘) l = len(arr) ans = "" i = l-1 while i>=0 and arr[i]==‘‘ : i=i-1 j = 0 while j<l and arr[j]==‘‘: j += 1 if i>=j: ans = arr[i] i = i-1 while i>=j : if arr[i]!=‘‘: ans = ans + " " + arr[i] i=i-1 return ans
标签:style blog io ar color sp for on div
原文地址:http://www.cnblogs.com/code-swan/p/4139566.html