20 Validate Parentheses
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user