边工作边刷题: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])
posted @ 2016-05-18 07:49  absolute100  阅读(93)  评论(0编辑  收藏  举报