Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- lastBracket = 0
- left = 0
- right = 0
- index = 0
- def violated_balanced(s):
- global lastBracket, left, right ,index
- if(index < len(s)):
- if s[index] == '(':
- left += 1
- lastBracket = index
- elif s[index] == ')':
- right += 1
- lastBracket = index
- index += 1
- return violated_balanced(s)
- else:
- if right != left:
- return index
- return -1
- def main():
- x = violated_balanced("t(())")
- print x
- # Here's our payoff idiom!
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment