Advertisement
biswasrohit20

bracket

Apr 4th, 2021
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. import sys
  2.  
  3. def validBrackets(string):
  4. # maintain balance of string
  5. bal = 0
  6. ans = 0
  7. for i in range(0, len(string)):
  8. if (string[i] == '('):
  9. bal += 1
  10. else:
  11. ans += 1
  12.  
  13. return abs(bal - ans)
  14.  
  15.  
  16. def main():
  17. # read the input String
  18. f = sys.stdin
  19. invalid = f.readline().strip()
  20. print(validBrackets(invalid))
  21.  
  22.  
  23. if __name__ == "__main__":
  24. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement