We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e93c1d0 commit ce4b722Copy full SHA for ce4b722
โvalid-parentheses/mangodm-web.py
@@ -0,0 +1,17 @@
1
+class Solution:
2
+ def isValid(self, s: str) -> bool:
3
+ """
4
+ - Idea: ์ฃผ์ด์ง ๋ฌธ์์ด์ ์ํํ๋ฉด์ ์ฌ๋ ๊ดํธ๋ ์คํ์ ๋ฃ๊ณ , ๋ซ๋ ๊ดํธ๋ ์คํ์ ์ต์๋จ ์์์ ๋งค์นญ๋๋์ง ํ์ธํ๋ค.
5
+ - Time Complexity: O(n), n์ ์ฃผ์ด์ง ๋ฌธ์์ด์ ๊ธธ์ด. ๋ชจ๋ ๋ฌธ์๋ฅผ ํ๋ฒ์ฉ์ ์ํํ๋ค.
6
+ - Space Complexity: O(n), ์ฃผ์ด์ง ๋ฌธ์์ด์ด ๋ชจ๋ ์ฌ๋ ๊ดํธ์ผ ๊ฒฝ์ฐ ์คํ์ ์ ์ฅ๋๋ค.
7
8
+ bracket_map = {"(": ")", "[": "]", "{": "}"}
9
+ stack = []
10
+
11
+ for char in s:
12
+ if char in bracket_map:
13
+ stack.append(char)
14
+ elif not stack or bracket_map[stack.pop()] != char:
15
+ return False
16
17
+ return not stack
0 commit comments