Again:confused by 'IndentationError: unexpected indent' with Python


  • 0
    X
    class Solution:
    # @param s, a string
    # @return a string
    def reverseWords(self, s):
    	lstOfstr = s.split()
    	lstOfstr.reverse()
    	return ' '.join(lstOfstr)

  • 0
    S

    Python is indent sensitive.

    Pay attention what we defined

    class Solution:
        # @param s, a string
        # @return a string
        def reverseWords(self, s):
    

    But your code is

    class Solution:
    # @param s, a string
    # @return a string
    def reverseWords(self, s):  # There is no indent before this line.
        lstOfstr = s.split()
        lstOfstr.reverse()
        return ' '.join(lstOfstr)
    

Log in to reply
 

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