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. 12月22日 update_columns,完成第9节。

    Update_columns(attributes) //等同于update_column 直接更新database. 使用UPdate SQL 语法. ⚠️ :忽略了validations, Cal ...

  2. Population Size CodeForces - 416D (贪心,模拟)

    大意: 给定$n$元素序列$a$, 求将$a$划分为连续的等差数列, 且划分数尽量小. $a$中的$-1$表示可以替换为任意正整数, 等差数列中必须也都是正整数. 贪心策略就是从前到后尽量添进一个等差 ...

  3. H.Playing games

    fwt #include<bits/stdc++.h> using namespace std; const int N=1<<19; const int mod=100000 ...

  4. (转载)-关于sg函数的理解

    最近学习了nim博弈,但是始终无法理解sg函数为什么sg[S]=mex(sg[S'] | S->S'),看到一篇博文解释的不错,截取了需要的几章节. 四.Sprague-Grundy数的提出 我 ...

  5. sql连接详解

    笛卡尔乘积: A={a, b},集合B={0, 1, 2},则AxB的笛卡尔积为{(a, 0), (a, 1), (a, 2), (b, 0), (b, 1), (b, 2)}; (AxB≠BxA) ...

  6. IDEA秒退或者一直让填写激活码问题

    IDEA秒退或者一直让填写激活码 1)复制  0.0.0.0 account.jetbrains.com 2)找到你本地的这个路径,我的电脑是windows,所以路径为: 3)点击hosts,添加刚刚 ...

  7. Nginx在windows上安装 及 Nginx的配置及优化

    https://www.cnblogs.com/Chiler/p/8027167.html http://www.runoob.com/linux/nginx-install-setup.html 前 ...

  8. Win10 dell驱动触摸板安装

    Win10 dell驱动触摸板安装 在此之前安装驱动后要重启

  9. html-中文字体在CSS中的显示(Unicode编码)(转载)

    为了方便需要的朋友快速使用,下表中列出了一些常用中文字体的Unicode编码: 宋体                   SimSun     \5B8B\4F53黑体                ...

  10. SQL Server 调优系列玩转篇一(如何利用查询提示(Hint)引导语句运行)

    前言 前面几篇我们分析了关于SQL Server关于性能调优的一系列内容,我把它分为两个模块. 第一个模块注重基础内容的掌握,共分7篇文章完成,内容涵盖一系列基础运算算法,详细分析了如何查看执行计划. ...