leetcode:Reverse Words in a String【Python版】
2014-10-15 23:30
351 查看
class Solution: # @param s, a string # @return a string def reverseWords(self, s): ss = s.split(" ") ss = filter(lambda x:x!="",ss) l = len(ss) for i in range(l/2): ss[i],ss[l-1-i] = ss[l-1-i],ss[i] s = (" ").join(ss) return s
为了去掉''字符,尝试了好几种方法,最后还是用filter函数将其过滤掉了。
相关文章推荐
- [leetcode, python] Reverse Words in a String 反转字符串
- [leetcode, python] Reverse Words in a String 反转字符串
- [leetcode, python] Reverse Words in a String 反转字符串
- [leetcode, python] Reverse Words in a String 反转字符串
- 151. Reverse Words in a String Leetcode Python
- [leetcode, python] Reverse Words in a String 反转字符串
- python:leetcode之reverse words in a string
- Leetcode - Python - Reverse Words in a String
- 【LeetCode with Python】 Reverse Words in a String
- [LeetCode]题解(python):151-Reverse Words in a String
- [leetcode, python] Reverse Words in a String 反转字符串
- [leetcode]Reverse Words in a String @ Python
- [leetcode]Reverse Words in a String(using Python)
- [leetcode, python] Reverse Words in a String 反转字符串
- [leetcode, python] Reverse Words in a String 反转字符串
- [leetcode, python] Reverse Words in a String 反转字符串
- leetcode 日经贴,python code -Reverse Words in a String
- 【leetcode】Reverse Words in a String (python)
- leetcode 【 Reverse Words in a String 】python 实现
- [leetcode, python] Reverse Words in a String 反转字符串