我的個人微信公衆號:Microstrong
微信公衆號ID:MicrostrongAI
微信公衆號介紹:Microstrong(小強)同學主要研究機器學習、深度學習、計算機視覺、智能對話系統相關內容,分享在學習過程中的讀書筆記!期待您的關注,歡迎一起學習交流進步!
知乎主頁:https://www.zhihu.com/people/MicrostrongAI/activities
題目鏈接:
題目描述:
解題思路:
已經AC的代碼:
class Solution:
def ReverseSentence(self, s):
s_list = s.split(" ")
s_list.reverse()
return " ".join(s_list)
def ReverseSentence2(self, s):
words = s.split(" ")
temp_sentence = []
for i in range(len(words) - 1, -1, -1):
temp_sentence.append(words[i])
return " ".join(temp_sentence)
if __name__ == '__main__':
sol = Solution()
s = "student. a am I"
print(sol.ReverseSentence2(s))