Skip to content

Commit b45e7f6

Browse files
committed
refactor: apply reviewer suggestions to valid-parentheses solution
1 parent bd7583d commit b45e7f6

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

valid-parentheses/jongwanra.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
Time: O(N), N = s.length
1313
Space: O(N), N = stack.length
1414
"""
15-
from os import popen
16-
1715

1816
class Solution:
1917
def isValid(self, s: str) -> bool:
@@ -23,11 +21,12 @@ def isValid(self, s: str) -> bool:
2321
# 여는 괄호인 경우 Stack 추가
2422
if bracket in bracket_dict:
2523
stack.append(bracket)
26-
continue
27-
2824
# 닫는 괄호인 경우
29-
if not stack or bracket_dict[stack.pop()] != bracket:
30-
return False
25+
else:
26+
if not stack:
27+
return False
28+
if bracket_dict[stack.pop()] != bracket:
29+
return False
3130

3231
return not stack
3332

@@ -44,3 +43,4 @@ def isValid(self, s: str) -> bool:
4443
print(sol.isValid("(") == False)
4544
print(sol.isValid("]") == False)
4645

46+

0 commit comments

Comments
 (0)