您的位置:首页 > 编程语言 > Python开发

[leetcode, python] Reverse Words in a String 反转字符串

2016-12-30 00:16 645 查看
问题描述:

Given an input string, reverse the string word by word.

For example,
Given s = "the sky is blue",
return "blue is sky the".


解决方案:

class Solution(object):
def reverseWords(self, s):
"""
:type s: str
:rtype: str
"""
s_list = s.strip().split()
re_s_list = s_list[::-1]
return " ".join(re_s_list)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python string leetcode