Created
January 26, 2020 09:30
-
-
Save inspirit941/7da13e7d85b47d4d7fdb702b334de694 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| arr = list(sys.stdin.readline()) | |
| stack = [] | |
| answer = 0 | |
| prev = None | |
| for i in range(len(arr)): | |
| if arr[i] == '(': | |
| stack.append(arr[i]) | |
| elif prev == '(' and arr[i] == ')': | |
| stack.pop() | |
| answer += len(stack) | |
| elif prev == ')' and arr[i] == ')': | |
| answer += 1 | |
| stack.pop() | |
| prev = arr[i] | |
| print(answer) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment