22 lines
543 B
Python
22 lines
543 B
Python
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
|