原题目
Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.
Example 1:
Input: "Let's take LeetCode contest" Output: "s'teL ekat edoCteeL tsetnoc"
Note: In the string, each word is separated by single space and there will not be any extra space in the string.
思路
第一遍解法
网上好的解法
def reverseWords(self, s):
return ' '.join(s.split()[::-1])[::-1]
自己可以改进的地方
最简代码