Valid Parentheses
Sat May 13 2023 07:08:24 GMT+0000 (Coordinated Universal Time)
Saved by
@Souvikdas
def isValid(s) :
stack = []
for i in s:
t= True
if i=="(" or i=="{" or i=="[":
stack.append(i)
elif i==')' and stack[-1]=="(":
stack.pop()
elif i=='}' and stack[-1]=="{":
stack.pop()
elif i==']' and stack[-1]=="[":
stack.pop()
else:
t= False
return t
print(isValid("()"))
content_copyCOPY
Comments