Created
April 23, 2026 14:05
-
-
Save ksamirdev/9d72b8d978c2b1e1b3e8a0e508ac9f11 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
| class Solution(object): | |
| def isValid(self, s): | |
| """ | |
| :type s: str | |
| :rtype: bool | |
| """ | |
| stack = [] | |
| closeToOpen = { | |
| ")" : "(", | |
| "]": "[", | |
| "}": "{" | |
| } | |
| for c in s: | |
| if c in closeToOpen: | |
| if stack and stack[-1] == closeToOpen[c]: | |
| stack.pop() | |
| else: | |
| return False | |
| else: | |
| stack.append(c) | |
| return len(stack) == 0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment