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函数将其过滤掉了。

相关文章:

  • 2022-01-27
  • 2021-10-17
  • 2021-08-21
猜你喜欢
  • 2022-02-07
  • 2021-10-03
  • 2021-12-03
相关资源
相似解决方案