Skip to content
Snippets Groups Projects
Commit 113d6041 authored by Pravesh's avatar Pravesh
Browse files

lab2 eval

parent 776fd635
Branches
No related tags found
No related merge requests found
def maxDepth(S):
current_max = 0
max = 0
n = len(S)
# Traverse the input string
for i in xrange(n):
if S[i] == '(':
current_max += 1
if current_max > max:
max = current_max
elif S[i] == ')':
if current_max > 0:
current_max -= 1
else:
return -1
# finally check for unbalanced string
if current_max != 0:
return -1
return max
s=input("Enter to check")
print maxDepth(s)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment