leetcode

Leetcode Solutions (0x6A73)
git clone https://git.pngu.org/leetcode
Log | Files | Refs | Submodules | README

reverse_word_string.py (457B)


# 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"))