本文主要是介绍leetcode151. Reverse Words in a String,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
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 ''
这篇关于leetcode151. Reverse Words in a String的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!