Skip to content

Commit 9249651

Browse files
committed
.
1 parent c978b1c commit 9249651

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Matching Brackets.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
def is_paired(input_string):
2+
open = ["(","{","["]
3+
close = [")","}","]"]
4+
result = True
5+
aux = []
6+
for char in input_string:
7+
if char not in open and char not in close:
8+
continue
9+
if char in open:
10+
aux.append(char)
11+
continue
12+
if len(aux) > 0:
13+
if close.index(char) != open.index(aux.pop()):
14+
result = False
15+
break
16+
continue
17+
result = False
18+
break
19+
return result and len(aux) == 0

0 commit comments

Comments
 (0)