Confused by 'IndentationError: unexpected indent' with Python


  • 2
    C

    class Solution:
    # @param s, a string
    # @return an integer

    def titleToNumber(self, s):
        length = len(s)
        letter = {
            'A': 1, 
    	    'B': 2,
    	    'C': 3,
            'D': 4,
    	    'E': 5,
    	    'F': 6,
    		'G': 7,
        	'H': 8,
    	    'I': 9,
    		'J': 10,
    		'K': 11,
    		'L': 12,
    		'M': 13,
    		'N': 14,
    		'O': 15,
    		'P': 16,
        	'Q': 17,
    	    'R': 18,
    	    'S': 19,
    	    'T': 20,
    		'U': 21,
        	'V': 22,
    	    'W': 23,
    	    'X': 24,
    		'Y': 25,
        	'Z': 26
        	}
        l = list (s)
    	i = 1
        result = 0
    
        for i in range (0, length):
    	    result =  result+ letter[l[i]] * pow(26, length - i - 1)
    
        return int(result)
    

    It always shows that Line 7: IndentationError: unexpected indent
    But I can run it in my TextWrangler. I am confused!


  • 0
    S

    I had been facing the same problem. The code editor of leetcode gets confused between tabs and spaces. The solution is to make tabs using spaces. There is an option in sublime text and I am sure there must be something similar in the Textwrangler as well.


Log in to reply
 

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