20 Validate Parentheses

This commit is contained in:
2024-07-14 08:55:32 -04:00
parent 9c65fc3bcf
commit 98d07c8e61
+21
View File
@@ -0,0 +1,21 @@
from collections import deque
class Solution:
def isValid(self, s: str) -> bool:
b_queue = deque()
for c in s:
if c == "[":
b_queue.append("]")
elif c == "(":
b_queue.append(")")
elif c == "{":
b_queue.append("}")
elif c in ["}", ")", "]"]:
if not len(b_queue) > 0:
return False
if c != b_queue.pop():
return False
return not len(b_queue) > 0