剑指offer全集详解python版——翻转单词顺序

题目描述:
例如,“student. a am I”。翻转后的句子应该是“I am a student.”。

思路:

它又想考原址性的,但python字符串不支持。

代码:

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

你可能感兴趣的:(算法,算法,剑指offer)