Select Git revision
RegisterActivity.java
cse16218_ex2_10.py 509 B
def depth(s, n):
current_max = 0
final_max = 0
for i in range(n):
if s[i] == '(':
current_max += 1
if current_max > final_max:
final_max = current_max
elif s[i] == ')':
if current_max > 0:
current_max -= 1
else: #unbalanced
return -1
if current_max != 0: #unbalanced
return -1
return final_max
s = input()
print (depth(s, len(s)))