文巾解题 557. 反转字符串中的单词 III
生活随笔
收集整理的這篇文章主要介紹了
文巾解题 557. 反转字符串中的单词 III
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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=0s2=''for i in s1:#print(i)s2+=is2+=' 's=copy.deepcopy(s2[:-1])return(s)總結
以上是生活随笔為你收集整理的文巾解题 557. 反转字符串中的单词 III的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 文巾解题 344 反转字符串
- 下一篇: NTU -SCSE-orientatio