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 e34f9af commit c1627a0Copy full SHA for c1627a0
1 file changed
โvalid-parentheses/gcount85.pyโ
@@ -0,0 +1,25 @@
1
+"""
2
+# Approach
3
+์คํ์ ์ด์ฉํ์ฌ ๋ซ๋ ๊ดํธ๊ฐ ๋์ฌ ๋ ์คํ top๊ณผ ๋น๊ตํ์ฌ ์ง์ด ๋ง์ผ๋ฉด popํฉ๋๋ค.
4
+์ง์ด ๋ง์ง ์์ผ๋ฉด invalid, ์ต์ข ์ ์ผ๋ก ์คํ์ด ๋น์ด์์ง ์์ผ๋ฉด invalid ํฉ๋๋ค.
5
+
6
+# Complexity
7
+s์ ๊ธธ์ด๋ฅผ N์ด๋ผ๊ณ ํ ๋
8
+- Time complexity: O(N)
9
+- Space complexity: O(N)
10
11
12
13
+class Solution:
14
+ def isValid(self, s: str) -> bool:
15
+ stack = []
16
+ brackets = {"(": ")", "{": "}", "[": "]"}
17
+ for b in s:
18
+ if b in brackets:
19
+ stack.append(b)
20
+ continue
21
+ if not stack or brackets[stack.pop()] != b:
22
+ return False
23
+ if not stack:
24
+ return True
25
0 commit comments