blob: 0c57902cea27f19d8bb8fed9486bebc877a4f1bf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
# 557. Reverse Words in a String III
"""
given a string 's', reverse the order of characters in each word within a
sentence while still preserving whitespace and initial word order
"""
class Solution(object):
def reverseWords(self, s):
return " ".join(map(lambda word: word[::-1], s.split()))
if __name__ == "__main__":
obj = Solution()
print(obj.reverseWords("Let's take Leetcode contest"))
print(obj.reverseWords("God Ding"))
|