剑指Offer44:翻转单词顺序列

思路:

先按空格将字符串转换成数组,然后从数组末尾元素加一个个加进去。

# -*- coding:utf-8 -*-
class Solution:
    def ReverseSentence(self, s):
        # write code here
        arr=s.split(" ")
        return " ".join(arr[::-1])

猜你喜欢

转载自blog.csdn.net/weixin_43160613/article/details/85677632