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.
这题没啥说的,python就是无脑split join就行。
class Solution(object):
def reverseWords(self, s):
"""
:type s: str
:rtype: str
"""
a = s.split()
b = []
for i in a:
b.append(i[::-1])
ans = ' '.join(b)
return ans
AC
网友评论