Why my code got compile error?


  • 0
    W
    import re
    
    class Solution:
        # @param s, a string
        # @return a string
        def reverseWords(self, s):
            return ' '.join(re.findall('[a-zA-Z]+', s)[::-1])

  • 0
    S

    Do not import anything, you could assume those necessary library have all imported. If you are still feeling that you cannot get rid of unsupported library, please email admin@leetcode.com about it.


  • 1
    H

    try

    class Solution:
    # @param s, a string
    # @return a string
    def reverseWords(self, s):
        result = " ".join(s.split()[::-1])
        return result

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.