mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 19:44:45 +08:00
添加151.翻转字符串里的单词 python版本
This commit is contained in:
@ -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
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user