leetcode:Reverse Words in a String【Python版】
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:Reverse Words in a String【Python版】的更多相关文章
- [leetcode]Reverse Words in a String @ Python
原题地址:https://oj.leetcode.com/problems/reverse-words-in-a-string/ 题意: Given an input string, reverse ...
- LeetCode: Reverse Words in a String:Evaluate Reverse Polish Notation
LeetCode: Reverse Words in a String:Evaluate Reverse Polish Notation Evaluate the value of an arithm ...
- [LeetCode] Reverse Vowels of a String 翻转字符串中的元音字母
Write a function that takes a string as input and reverse only the vowels of a string. Example 1:Giv ...
- [LeetCode] Reverse Words in a String II 翻转字符串中的单词之二
Given an input string, reverse the string word by word. A word is defined as a sequence of non-space ...
- [LeetCode] Reverse Words in a String 翻转字符串中的单词
Given an input string, reverse the string word by word. For example, Given s = "the sky is blue ...
- LeetCode Reverse Words in a String II
原题链接在这里:https://leetcode.com/problems/reverse-words-in-a-string-ii/ 题目: Given an input string, rever ...
- [LeetCode] Reverse Words in a String III 翻转字符串中的单词之三
Given a string, you need to reverse the order of characters in each word within a sentence while sti ...
- LeetCode: Reverse Words in a String 解题报告
Reverse Words in a String Given an input string, reverse the string word by word. For example,Given ...
- LeetCode Reverse Vowels of a String
原题链接在这里:https://leetcode.com/problems/reverse-vowels-of-a-string/ 题目: Write a function that takes a ...
随机推荐
- LeetCode--217--存在重复元素
问题描述: 给定一个整数数组,判断是否存在重复元素. 如果任何值在数组中出现至少两次,函数返回 true.如果数组中每个元素都不相同,则返回 false. 示例 1: 输入: [1,2,3,1] 输出 ...
- 20170112xlVBA查询SQL
Sub NextSeven_CodeFrame() '应用程序设置 Application.ScreenUpdating = False Application.DisplayAlerts = Fal ...
- 使用XML Publisher导出PDF报表
生成XML数据源有两种方式. 一种是使用存储过程,返回一个clob作为xml数据源. 另一种是直接使用VO中的数据生成xml数据源. 方法一参考: Oracle XML Publisher技巧集锦 O ...
- java连接MySql数据库 zeroDateTimeBehavior
JAVA连接MySQL数据库,在操作值为0的timestamp类型时不能正确的处理,而是默认抛出一个异常, 就是所见的:java.sql.SQLException: Cannot convert va ...
- arcTo
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head> < ...
- ubuntu下安装go语言;sublime+gocode搭建;go的卸载和环境变量配个人.bashrc;2空位3个网
https://blog.csdn.net/needkane/article/details/36891949 https://www.jianshu.com/p/4f79ae4f081c http: ...
- 亿图图示与visio结合使用
亿图图示与visio结合使用 Model 图例 思维导图 Camp Awards 思维导图 思维导图 Englilsh camp activity plan 项目管理 Auto WBS 商务 错误 ...
- Excel中输入身份证后3位变成0,怎么办?
1.问题介绍: 1)问题: 在使用excel输入身份证号时,会发现直接输入数字后最后面的三位数字都变成0了,这可怎么办呢?
- SQL中游标的使用(转)
http://www.cnblogs.com/tianguook/archive/2011/03/09/1977987.html 一般情况下,我们用SELECT这些查询语句时,都是针对的一行记录而言, ...
- windows10自动登陆
老是记不住命令,记录一下 win+R 输入以下命令 Control Userpasswords2