【LeetCode OJ】Reverse Words in a String

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

上一篇:js removeChild 方法


下一篇:c#编程-线程同步