u6
This commit is contained in:
parent
c8bb132585
commit
27305dd122
18
u6/matching_brackets.py
Normal file
18
u6/matching_brackets.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
def is_paired(seq: str) -> bool:
|
||||||
|
stack = []
|
||||||
|
|
||||||
|
open_brackets = "([{"
|
||||||
|
close_brackets = ")]}"
|
||||||
|
|
||||||
|
for ch in seq:
|
||||||
|
if(ch in open_brackets):
|
||||||
|
stack.append(ch)
|
||||||
|
continue
|
||||||
|
|
||||||
|
matched_closed = close_brackets.find(ch)
|
||||||
|
if(matched_closed != -1):
|
||||||
|
if(not len(stack) or stack[-1] != open_brackets[matched_closed]):
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
stack.pop()
|
||||||
|
return not len(stack)
|
||||||
Loading…
Reference in New Issue
Block a user