-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrackte_matcher.py
More file actions
28 lines (24 loc) · 888 Bytes
/
brackte_matcher.py
File metadata and controls
28 lines (24 loc) · 888 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""Bracket Matcher
Have the function BracketMatcher(str) take the str parameter being passed and return 1
if the brackets are correctly matched and each one is accounted for. Otherwise return 0.
For example: if str is "(hello (world))", then the output should be 1, but if str is
"((hello (world))" the the output should be 0 because the brackets do not correctly match up.
Only "(" and ")" will be used as brackets. If str contains no brackets return 1.
Examples
Input: "(coder)(byte))"
Output: 0
Input: "(c(oder)) b(yte)"
Output: 1 """
def BracketMatcher(strParam):
count = 0
for c in strParam:
if c == '(':
count += 1
elif c == ')':
count -= 1
if count < 0:
return 0
return 1 if count == 0 else 0
# keep this function call here
bracket="the color re(d))()(()"
print(BracketMatcher(bracket))