Brackets 100% Solution in python

Question

app.codility.com

My Solution

app.codility.com

def solution(S):
    
    stack = [0]*len(S)
    size = 0
    
    for i in range(len(S)):
        if S[i] is "(" or S[i] is "{" or S[i] is "[":
            stack[size] = S[i]
            size += 1
        else: 
            if size is 0:
                return 0
            elif S[i] is ")" and stack[size-1] is "(":
                size -=1
            elif S[i] is "}" and stack[size-1] is "{":
                size -=1
            elif S[i] is "]" and stack[size-1] is "[":
                size -=1
    
    if size is 0:
        return 1
    
    return 0

Note

Classic brackets pairing usually comes up with stack solution.