Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- def validBrackets(string):
- # maintain balance of string
- bal = 0
- ans = 0
- for i in range(0, len(string)):
- if (string[i] == '('):
- bal += 1
- else:
- ans += 1
- return abs(bal - ans)
- def main():
- # read the input String
- f = sys.stdin
- invalid = f.readline().strip()
- print(validBrackets(invalid))
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement