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 ...
随机推荐
- English trip -- VC(情景课)2 B Classroom objects
Vocabulary focus 核心词汇 Listen and repeat. 听并跟读 1. a dictionary 2. paper 3. a pen 4. a ruler 5. a stap ...
- php--------文件夹文件拷贝和复制
php开发中常常对文件进行操作,文件夹和文件的拷贝,复制等. /** * 文件夹文件拷贝 * * @param string $src 来源文件夹 * @param string $dst 目的地文件 ...
- Confluence 6 配置 LDAP 连接池
当 LDAP 连接池被启用后,LDAP 目录服务器将会维护一个连接池同时当必要的时候指派他们.当一个连接关闭后,这个连接将会放回到连接池中供以后进行使用.这种设置将会有效的提高系统性能. 希望配置 L ...
- 『cs231n』作业2选讲_通过代码理解优化器
1).Adagrad一种自适应学习率算法,实现代码如下: cache += dx**2 x += - learning_rate * dx / (np.sqrt(cache) + eps) 这种方法的 ...
- svn拒绝连接
svn 服务开启: svnserve -d -r /home/svn
- ajax乱码解决汇总
ajax乱码解决总结第一,javascript沿用java的字符处理方式,内部是使用unicode来处理所有字符的,第二,utf-8是每个汉字(unicode字符)用3个字节来存储.第三,用utf-8 ...
- SSH执行远程命令和传送数据
$ ssh user@host 'mkdir -p .ssh && cat >> .ssh/authorized_keys' < ~/.ssh/id_rsa.pub ...
- Deep Belief Network简介——本质上是在做逐层无监督学习,每次学习一层网络结构再逐步加深网络
from:http://www.cnblogs.com/kemaswill/p/3266026.html 1. 多层神经网络存在的问题 常用的神经网络模型, 一般只包含输入层, 输出层和一个隐藏层: ...
- NRF51822+STM32bootload——typedef void (*Fun) (void) 理解
1.typdef 用法如下所示 typedef unsigned char uint8_t; typedef unsigned short int uint16_t; typedef unsigned ...
- BZOJ一天提交(AC) 51纪念
像我这种蒟蒻...一天交了51道题也要纪念... 真是...但是.不知道还有没有机会了... 这样子就会有很多题解要补了...慢慢来吧... 另.AC数已经超过500了还真是历史性的一步啊...