Valid Parenthesis in an mathematical expression.
Anonymous
class Solution: def isValid(self, s: str) -> bool: stack = [] paranthesis_exp = { "}" : "{", "]" : "[", ")" : "(" } for char in s: if char in paranthesis_exp.values(): stack.append(char) elif char in paranthesis_exp.keys(): if not stack or stack[-1] != paranthesis_exp[char]: return False stack.pop() return len(stack) == 0
Check out your Company Bowl for anonymous work chats.