Python Solution


  • 0
    Y
        def calPoints(self, A):
            """
            :type ops: List[str]
            :rtype: int
            """
            n=len(A)
            res=0
            valid=[]
            for i in xrange(n):
                if A[i]=="C":
                    res-=valid[-1]
                    valid.pop()
                elif A[i]=="D":
                    valid.append(valid[-1]*2)
                    res+=valid[-1]
                elif A[i]=="+":
                    valid.append(valid[-1]+valid[-2])
                    res+=valid[-1]
                else: 
                    valid.append(int(A[i]))
                    res+=int(A[i])
            return res
    

Log in to reply
 

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