1 题目描述
2 解题思路
2.1 单词倒转+使用join函数
import copy
class Solution(object):
def reverseWords(self, s):
"""
:type s: str
:rtype: str
"""
return " ".join(word[::-1] for word in s.split(" "))
2.2 单词倒转+使用辅助数组
import copy
class Solution(object):
def reverseWords(self, s):
"""
:type s: str
:rtype: str
"""
s1=s.split()
for i in range(len(s1)):
s1[i]=s1[i][::-1]
#print(s1)
index=0
s2=''
for i in s1:
#print(i)
s2+=i
s2+=' '
s=copy.deepcopy(s2[:-1])
return(s)