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 de096ec commit 95d9c8aCopy full SHA for 95d9c8a
โvalid-parentheses/Seoya0512.pyโ
@@ -0,0 +1,18 @@
1
+'''
2
+20. Valid Parentheses
3
+Stack์ ์ฌ์ฉํ๋ ๋ฌธ์ ์์ ํ์ ํ์ง ๋ชปํด์ ๊ฒฐ๊ตญ ์๊ณ ๋ฌ๋ ๋์ ๋์์ ๋ฐ์์ต๋๋ค.
4
+
5
+Time Complexity: O(n)
6
+Space Complexity: O(n)
7
8
+class Solution:
9
+ def isValid(self, s: str) -> bool:
10
+ parens = {"(": ")", "{": "}", "[": "]"}
11
+ stack = []
12
+ for val in s:
13
+ if val in parens:
14
+ stack.append(val)
15
+ else:
16
+ if not stack or val != parens[stack.pop()]:
17
+ return False
18
+ return not stack
0 commit comments