边工作边刷题:70天一遍leetcode: day 7

Reverse Words in a String

不知道为什么in-place的会超时,不过这题也没要求,做II的时候看看还超不超时。这题可以one-liner:return " ".join(s.split()[::-1])

class Solution(object):
    def reverseWords(self, s):
        """
        :type s: str
        :rtype: str
        """
        return " ".join(s.split()[::-1])
原文地址:https://www.cnblogs.com/absolute/p/5582675.html