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 1bc8c62 commit 065a79dCopy full SHA for 065a79d
βvalid-parentheses/KwonNayeon.pyβ
@@ -1 +1,27 @@
1
+"""
2
+Constraints:
3
+1. 1 <= s.length <= 10^4
4
+2. s consists of parentheses only '()[]{}'
5
6
+Time Complexity: O(n)
7
+- λ¬Έμμ΄μ κ° λ¬Έμλ₯Ό ν λ²μ©λ§ μννλ―λ‘ O(n)
8
+- κ° λ¬Έμμ λν μ°μ°(push, pop)μ O(1)
9
+
10
+Space Complexity: O(n)
11
+- μ΅μ μ κ²½μ° λͺ¨λ λ¬Έμκ° μ¬λ κ΄νΈμΌ λ μ€νμ λͺ¨λ μ μ₯
12
+- λ°λΌμ μ λ ₯ ν¬κΈ°μ λΉλ‘νλ O(n) κ³΅κ° νμ
13
14
+class Solution:
15
+ def isValid(self, s: str) -> bool:
16
+ stack = []
17
+ pairs = {')': '(', '}': '{', ']': '['}
18
19
+ for char in s:
20
+ if char in '({[':
21
+ stack.append(char)
22
+ else:
23
+ if not stack or stack[-1] != pairs[char]:
24
+ return False
25
+ stack.pop()
26
27
+ return len(stack) == 0
0 commit comments