Problem link:

http://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".

LeetCode OJ supports Python now!

The solution for this problem is extremely easy... What you need is only three build-in methods: string.split(), string.join(), and list.reverse().

class Solution:
# @param s, a string
# @return a string
def reverseWords(self, s):
res = s.split()
res.reverse()
return " ".join( res )

That is it...

【LeetCode OJ】Reverse Words in a String的更多相关文章

  1. 【LeetCode练习题】Reverse Words in a String

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

  2. 【LeetCode OJ】Word Ladder I

    Problem Link: http://oj.leetcode.com/problems/word-ladder/ Two typical techniques are inspected in t ...

  3. 【LeetCode OJ】Palindrome Partitioning II

    Problem Link: http://oj.leetcode.com/problems/palindrome-partitioning-ii/ We solve this problem by u ...

  4. 【LeetCode OJ】Palindrome Partitioning

    Problem Link: http://oj.leetcode.com/problems/palindrome-partitioning/ We solve this problem using D ...

  5. 【LeetCode OJ】Valid Palindrome

    Problem Link: http://oj.leetcode.com/problems/valid-palindrome/ The following two conditions would s ...

  6. 【LeetCode OJ】Interleaving String

    Problem Link: http://oj.leetcode.com/problems/interleaving-string/ Given s1, s2, s3, find whether s3 ...

  7. 【LeetCode OJ】Evaluate Reverse Polish Notation

    Problem link: http://oj.leetcode.com/problems/evaluate-reverse-polish-notation/ According to the wik ...

  8. 【LeetCode OJ】Binary Tree Zigzag Level Order Traversal

    Problem Link: https://oj.leetcode.com/problems/binary-tree-zigzag-level-order-traversal/ Just BFS fr ...

  9. 【LEETCODE OJ】Reorder List

    Problem link: http://oj.leetcode.com/problems/reorder-list/ I think this problem should be a difficu ...

随机推荐

  1. hdu----(4545)魔法串(LCS)

    魔法串 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submiss ...

  2. Remove Nth Node From End of List [LeetCode]

    Given a linked list, remove the nth node from the end of list and return its head. For example, Give ...

  3. NSException

    NSException是什么? 最熟悉的陌生人,这是我对NSException的概述,为什么这么说呢?其实很多开发者接触到NSException的频率非常频繁,但很多人都不知道什么是NSExcepti ...

  4. 直接取HANA数据库数据,动态QUERY

    "COPY别人的TYPE-POOLS:ADBC. DATA LV_SQL TYPE STRING. DATA LV_FROM TYPE STRING. DATA LV_WHERE TYPE ...

  5. VS输入输出基本操作以及数据类型和类型转换

    (一)   C#项目的组成结构 项目结构 .config ---配置文件(存放配置参数文件) .csproj ---项目文件(管理文件项) .sln   ---解决方案文件(管理项目) .cs   - ...

  6. 电脑的基本硬件知识以及unix图解

    1.DELL R720 R610 2.电源: 人体心脏3.硬盘: 存数据的地方.机械的性能不高,3.5英寸 性能 SATA 借口<SAS <SSD 价格:SSD> SAS>SA ...

  7. wordpress 中禁止更新提示

    前言: 在此之前每每打开blog的时候总是有那么个数字在那边显示,如果是很重要的更新显示在那也就算了,有时候就算一个破主题他还一直在那边,很是让小猪纠结.最关键的是要是更新了主题,那么之前所有自定义的 ...

  8. Activity界面切换动画特效。

    效果图: 结构图: 测试代码: 布局: 1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearL ...

  9. [转载]Android 编译环境 build/envsetup.sh分析

    2013-12-23 11:28:40 转载自: http://blog.csdn.net/evilcode/article/details/7005757 请到转载地址阅读原文, 转载以备查询.

  10. Linux gcc编译(动态库,静态库)

    1. linux 库路径: /lib , /usr/lib , /usr/local/lib 2.linux 编译静态库 a.编写源文件vi pr1.c void print1(){    print ...