Problem List
I completed this problem the same time that we were going over stacks in DSA. So when I came across it I immediately knew that a stack would be necessary to complete this problem. At some point I will need to redo it in Go instead of Python, however I had just written a delimeter check for a project, so python was the most straight forward approach.
class Solution:
def isValid(self, s: str) -> bool:
stack = []
open_brackets = ["[", "{", "("]
for c in s:
if c in open_brackets:
stack.append(c)
elif c == "}" and stack and stack[-1] == "{":
stack.pop()
elif c == "]" and stack and stack[-1] == "[":
stack.pop()
elif c == ")" and stack and stack[-1] == "(":
stack.pop()
else:
return False
return len(stack) == 0