标签:style color os io strong for ar 问题
问题描述:
Given an input string, reverse the string word by word.
For example,
Given s = "the sky is blue
",
return "blue is sky the
".
解题思路:
先利用split()方法将句子按空格分为几个单词的列表,
然后reverse()函数使列表逆序,
最后join函数以空格为间隔拼成字符串返回结果。
Python代码:
class Solution:
# @param s, a string
# @return a string
def reverseWords(self, s):
a = s.split()
a.reverse()
return ‘ ‘.join(a)
LeetCode OJ1:Reverse Words in a String,布布扣,bubuko.com
LeetCode OJ1:Reverse Words in a String
标签:style color os io strong for ar 问题
原文地址:http://www.cnblogs.com/Evermaple/p/3916124.html