美文网首页
Reverse Words in a String III

Reverse Words in a String III

作者: 腹黑君 | 来源:发表于2017-07-22 23:33 被阅读0次

    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

    相关文章

      网友评论

          本文标题: Reverse Words in a String III

          本文链接:https://www.haomeiwen.com/subject/qolpkxtx.html