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版】的更多相关文章

  1. [leetcode]Reverse Words in a String @ Python

    原题地址:https://oj.leetcode.com/problems/reverse-words-in-a-string/ 题意: Given an input string, reverse ...

  2. 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 ...

  3. [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 ...

  4. [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 ...

  5. [LeetCode] Reverse Words in a String 翻转字符串中的单词

    Given an input string, reverse the string word by word. For example, Given s = "the sky is blue ...

  6. LeetCode Reverse Words in a String II

    原题链接在这里:https://leetcode.com/problems/reverse-words-in-a-string-ii/ 题目: Given an input string, rever ...

  7. [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 ...

  8. LeetCode: Reverse Words in a String 解题报告

    Reverse Words in a String Given an input string, reverse the string word by word. For example,Given ...

  9. LeetCode Reverse Vowels of a String

    原题链接在这里:https://leetcode.com/problems/reverse-vowels-of-a-string/ 题目: Write a function that takes a ...

随机推荐

  1. English trip -- VC(情景课)1 C What's your name?(review)

    Xu言: 今天,阴差阳错又上了一次 VC 1 C的课,不过这次是小班的形式.这次课的教室叫 toronto   [təˈrɒntəʊ]  to ron to (多伦多(加拿大城市))   - -0我还 ...

  2. Enduring Exodus CodeForces - 655C (二分)

    链接 大意: n个房间, 1为占用, 0为未占用, John要将k头奶牛和自己分进k+1个空房间, 求John距最远的奶牛距离的最小值 这种简单题卡了20min.... 显然对于固定的k+1个房间, ...

  3. java MongoDB查询(一)简单查询

    前言 MongoDB的java驱动提供了查询的功能,查询条件也是bson对象,这篇就看下怎么进行简单的数据查询 1.数据结构 集合:firstCollection 数据内容: { "_id& ...

  4. 使用POI导入EXCEL报java.lang.IncompatibleClassChangeError

    使用POI导入xls格式的excel报java.lang.IncompatibleClassChangeError异常,而导入xlsx正常. oracle.apps.fnd.framework.OAE ...

  5. 设置MyEclipse字体大小

    设置MyEclipse字体大小

  6. 动态链接库DLL_第1篇

    动态链接库通常不能直接运行,也不能接收消息.它们是一些独立的文件,其中包含能被可执行程序或其他DLL调用来完成某项工作的函数.只有在其他模块调用动态链接库中的函数时,它才发挥作用.实际编程时,可把完成 ...

  7. PHP程序后台自动运行

    如何让php程序自动执行,这个就需要用到一个函数了: int ignore_user_abort ( [bool setting] ) 定义和用法ignore_user_abort() 函数设置与客户 ...

  8. IOS消息推送(转)

    第一部分 首先第一步当然是介绍一下苹果的推送机制(APNS)咯(ps:其实每一篇教程都有),先来看一张苹果官方对其推送做出解释的概要图. Provider是给你手机应用发出推送消息的服务器,而APNS ...

  9. cocos2dx 不同平台上加载文件

    原文转自:http://blog.sina.com.cn/s/blog_62b2318d0101eozt.html cocos2dx在不同平台上读取资源文件时的处理方式是不同的. 在ios下,程序调用 ...

  10. 解决 Error: could not open `C:\Program Files\Java\jre7\lib\i386\jvm.cfg'

    解决 Error: could not open `C:\Program Files\Java\jre7\lib\i386\jvm.cfg' 重装JDK后,因为没有装在以前的目录,运行java命令后报 ...