Created
January 20, 2026 08:10
-
-
Save maehrm/fb788568888f604e7a0f84e42d2e4d40 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
| def solv(): | |
| stack = [] | |
| c_set = set() | |
| for c in S: | |
| if c == "(": | |
| stack.append(c) | |
| elif c == ")": | |
| while stack and stack[-1] != "(": | |
| ch = stack.pop() | |
| c_set.remove(ch) | |
| stack.pop() | |
| else: | |
| if c in c_set: | |
| return False | |
| c_set.add(c) | |
| stack.append(c) | |
| return True | |
| S = list(input()) | |
| print("Yes") if solv() else print("No") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment