Skip to content

Commit d5be9c8

Browse files
committed
leetcode.com 20. Valid Parentheses
문제 링크: https://leetcode.com/problems/valid-parentheses
1 parent 34219d1 commit d5be9c8

File tree

1 file changed

+19
-0
lines changed
  • leetcode.com 20. Valid Parentheses v2

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution:
2+
def isValid(self, s: str) -> bool:
3+
dt = []
4+
5+
for c in s:
6+
if len(dt) == 0:
7+
dt.append(c)
8+
continue
9+
10+
if dt[-1] == '(' and c == ')':
11+
dt.pop()
12+
elif dt[-1] == '[' and c == ']':
13+
dt.pop()
14+
elif dt[-1] == '{' and c == '}':
15+
dt.pop()
16+
else:
17+
dt.append(c)
18+
19+
return True if len(dt) == 0 else False

0 commit comments

Comments
 (0)