Skip to content

Commit 61d582f

Browse files
committed
feat: valid-parentheses
1 parent 132b69e commit 61d582f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

valid-parentheses/HodaeSsi.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# 시간 복잡도 : O(n)
2+
# 공간 복잡도 : O(n)
3+
# 문제 유형 : Stack
4+
class Solution:
5+
def isValid(self, s: str) -> bool:
6+
stack = []
7+
8+
for char in s:
9+
if char in (')', '}', ']'):
10+
if not stack or stack.pop() != {')': '(', '}': '{', ']': '['}[char]:
11+
return False
12+
else:
13+
stack.append(char)
14+
15+
return not stack
16+

0 commit comments

Comments
 (0)