原题地址:https://oj.leetcode.com/problems/reverse-words-in-a-string/

题意:

Given an input string, reverse the string word by word.

For example,
Given s = "the sky is blue",
return "blue is sky the".

解题思路:这题很能体现python处理字符串的强大功能。

代码:

class Solution:
# @param s, a string
# @return a string
def reverseWords(self, s):
return " ".join(s.split()[::-1])

[leetcode]Reverse Words in a String @ Python的更多相关文章

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

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

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

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

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

  5. LeetCode Reverse Words in a String II

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

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

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

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

  8. leetcode:Reverse Words in a String【Python版】

    class Solution: # @param s, a string # @return a string def reverseWords(self, s): ss = s.split(&quo ...

  9. LeetCode Reverse Vowels of a String

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

随机推荐

  1. html5解决ajax破坏浏览器机制

    pjax是一种基于ajax+history.pushState的新技术,该技术可以无刷新改变页面的内容,并且可以改变页面的URL.pjax是ajax+pushState的封装,同时支持本地存储.动画等 ...

  2. UVALive 6915 Leveling Ground 倍增RMQ

    Leveling Ground 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid ...

  3. 解决 MyEclipse build workspace 慢,validation javascript 更慢的问题

    自从升级了MyEclipse到7.0,项目Build的时候总是很慢,显示Validating 那些js,html文件.不管我怎么调整 Windows > Preference > MyEc ...

  4. 一、java概述

    一.概述 java不仅仅是一门编程语言,还是一个由一系列计算机软件和规范形成的技术体系. 提供了完整的开发和跨平台部署的支持环境.用途广泛.     结构严谨.面向对象.摆脱硬件平台的束缚.     ...

  5. VMware vmdk文件打开方法

    打开虚拟机设置——硬盘——映射,把虚拟机磁盘文件vmdk映射到系统中即可!

  6. C# 判断字符编码的六种方法

    方法一http://blog.csdn.net/qiujiahao/archive/2007/08/09/1733169.aspx在unicode 字符串中,中文的范围是在4E00..9FFF:CJK ...

  7. uva 10154 - Weights and Measures【dp】qi

    题意:uva 10154 - Weights and Measures 题意:有一些乌龟有一定的体重和力量,求摞起来的最大高度.力量必须承受其上面包含自己的所有的重量. 分析:先按其能举起来的力量从小 ...

  8. ZOJ 2702 Unrhymable Rhymes 贪心

    贪心.能凑成一组就算一组 Unrhymable Rhymes Time Limit: 10 Seconds      Memory Limit: 32768 KB      Special Judge ...

  9. LPC43xx OTP

  10. PE Header and Export Table for Delphi

    Malware Analysis Tutorial 8: PE Header and Export Table 2. Background Information of PE HeaderAny bi ...