Always get unexpected indent with Python


  • 1
    X
    class Solution:
    # @param tokens, a list of string
    # @return an integer
    def evalRPN(self, tokens):
    	oper = {
    	'+':lambda x,y:x+y,
    	'-':lambda x,y:x-y,
    	'*':lambda x,y:x*y,
    	'/':lambda x,y:int(x/y)
    	}
    	stk = []
    	for item in tokens:
    		if item not in ['+','-','*','/']:
    			stk.append(int(item))
    		else:
    			op2 = stk.pop()
    			op1 = stk.pop()
    			stk.append(oper[item](op1,op2))
    	return stk[0]

Log in to reply
 

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