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. 關於my97datepicker

    原因的一篇是比較老的版本了 目前使用4.72 目前碰到一種情況就是使用了PopUpForm.js,也就是在頁面中彈出一個框,用來編輯,或者添加數據等功能. 使用知道時間會出現一種情況.時間顯示被ifr ...

  2. finally块中的代码一定会执行吗?

    在Sun Tutorial中有这样一句话:The finally block always executes when the try block exits. This ensures that t ...

  3. [转载]SAP BASIS学习手册

    原文地址:SAP BASIS学习手册作者:sapren     1:)要用scc4定义一个新的client,同时定义好类型(T,P,D等) 2:)用user/pasword: (sap*/pass) ...

  4. 5月21日 CSS样式表加阴影

    HTML <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3 ...

  5. [转]C#设置WinForm快捷键

    1.Alt+*(按钮快捷键)按钮快捷键也为最常用快捷键,其设置也故为简单.在大家给button.label.menuStrip等其他控件的Text属性指定名称时,在其后面加上‘&’然后在加上一 ...

  6. windows下mysql主从同步备份步骤

    目的:有两台MySQL数据库服务器A和B,使A为主服务器,B为从服务器,初始状态时,A和B中的数据信息相同,当A中的数据发生变化时,B也跟着发生相应的变化,使得A和B的数据信息同步,达到备份的目的. ...

  7. 使用drawBitmapMesh扭曲图像

    Canvas提供了一个drawBitmapMesh(bitmap, meshWidth, meshHeight, verts, vertOffset, colors, colorOffset, pai ...

  8. bzoj 2661: [BeiJing wc2012]连连看

    #include<cstdio> #include<iostream> #include<cstring> #include<cmath> #inclu ...

  9. 2.4.2电子书fb.c文件

    显示层面头文件 定义结构体,为显示统一标准 int (*DeviceInit)(void); 显示类驱动初始化 int (*ShowPixel)(int iPenX, int iPenY, unsig ...

  10. java jar

    http://www.cnblogs.com/shirui/p/5270969.html Java之 将程序打包成jar包   准备材料: 1.java文件: Helloworld.java pack ...