Brain Structural Validation / Validate Markdown Structure & Links (push) Failing after 8s
14 lines
334 B
Python
14 lines
334 B
Python
class Solution:
|
|
def isValid(self, string: str) -> bool:
|
|
pairs = {"(": ")", "{": "}", "[": "]"}
|
|
|
|
stack = []
|
|
|
|
for char in string:
|
|
if char in pairs:
|
|
stack.append(pairs[char])
|
|
elif not stack or stack.pop() != char:
|
|
return False
|
|
|
|
return not stack
|