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

来源:互联网 发布:java 队列 编辑:程序博客网 时间:2024/05/17 04:01

问题描述:

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)
0 0
原创粉丝点击