Skip to content

151 reverse words in a string

151. Reverse Words in a String

题目: https://leetcode.com/problems/reverse-words-in-a-string/

难度: Medium

太简单了

class Solution(object):
    def reverseWords(self, s):
        """
        :type s: str
        :rtype: str
        """
        tmp = s.split()
        res = " ".join(tmp[::-1])
        return res

class Solution(object):
    def reverseWords(self, s):
        """
        :type s: str
        :rtype: str
        """
        tmp = s.split()
        tmp.reverse()
        res = " ".join(tmp)
        return res


我们一直在努力

apachecn/AiLearning

【布客】中文翻译组