leetcode151. Reverse Words in a String

来源:互联网 发布:数据服务的公司 编辑:程序博客网 时间:2024/05/21 10:40

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        """        tmp=s.split(' ')        tmp.reverse()        ret=[]        for i in tmp:            if i!='':                ret.append(i)        if len(ret):            return ' '.join(ret)        else:            return ''
0 0
原创粉丝点击