Difference between online judgement and IDE


  • 0
    L
    class Solution:
    # @return a boolean
    def isValid(self, s):
        stack = []
        for i in range(len(s)):
            if s[i] == '(' or s[i] == '[' or s[i] == '{':
                stack.append(s[i])
            if s[i] == ')':
                if stack == [] or stack.pop() != '(':
                    return False
            if s[i] == ']':
                if stack == [] or stack.pop() != '[':
                    return False
            if s[i] == '}':
                if stack == [] or stack.pop() != '{':
                    return False
        if stack:
            return False
        else:
            return True
    

    But if I replace the stack.pop() != '[' by stack.pop() is not '[': it will misjudge...


Log in to reply
 

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