原題地址: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])