标签:style blog color io ar for sp div on
1 class Solution: 2 # @param s, a string 3 # @return a string 4 def reverseWords(self, s): 5 ss = s.split(" ") 6 ss = filter(lambda x:x!="",ss) 7 l = len(ss) 8 for i in range(l/2): 9 ss[i],ss[l-1-i] = ss[l-1-i],ss[i] 10 s = (" ").join(ss) 11 return s
为了去掉‘‘字符,尝试了好几种方法,最后还是用filter函数将其过滤掉了。
leetcode:Reverse Words in a String
标签:style blog color io ar for sp div on
原文地址:http://www.cnblogs.com/CheeseZH/p/4027710.html