Can I change the function signature?

  • 0

    Why the following codes can not be accepted by can pass the test cases?

    class Solution(object):
        def calculate(self, s, p=[0]):
            :type s: str
            :rtype: int
            if not s:
                return 0
            value, num, op, i = 0, 0, 1, p[0]
            while i<len(s):
                ch = s[i]
                #print 'ch = %s' % ch
                if ch=='+':
                    value, num, op, i = op*num+value, 0, 1, i+1
                elif ch=='-':
                    value, num, op, i = op*num+value, 0, -1, i+1
                elif ch=='(':
                    p[0] = i+1
                    value = value+op*self.calculate(s, p)
                    i = p[0]
                elif ch==')':
                    p[0] = i+1
                    return value+op*num
                elif ch==' ':
                    i += 1
                    #print 1, num
                    num, i= 10*num + int(ch), i+1
                    #print 2, num
            return value+op*num        

Log in to reply

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