添加151.翻转字符串里的单词 python版本

This commit is contained in:
yff-1996
2021-06-15 18:42:59 +08:00
parent c79cc48454
commit 3a2ab58846

View File

@ -359,10 +359,10 @@ class Solution:
return None return None
#4.翻转字符串里的单词 #4.翻转字符串里的单词
def reverseWords(self, s): #测试用例:"the sky is blue def reverseWords(self, s): #测试用例:"the sky is blue"
l = self.trim_spaces(s) #输出:"the sky is blue" l = self.trim_spaces(s) #输出:['t', 'h', 'e', ' ', 's', 'k', 'y', ' ', 'i', 's', ' ', 'b', 'l', 'u', 'e'
self.reverse_string( l, 0, len(l) - 1) #输出:"blue is sky the" self.reverse_string( l, 0, len(l) - 1) #输出:['e', 'u', 'l', 'b', ' ', 's', 'i', ' ', 'y', 'k', 's', ' ', 'e', 'h', 't']
self.reverse_each_word(l) #输出:"blue is sky the" self.reverse_each_word(l) #输出:['b', 'l', 'u', 'e', ' ', 'i', 's', ' ', 's', 'k', 'y', ' ', 't', 'h', 'e']
return ''.join(l) #输出blue is sky the return ''.join(l) #输出blue is sky the