Skip to content

Commit f1a2829

Browse files
committed
[edit] valid parentheses solution - stack 비었을 때 고려해서 수정
1 parent f72bfa3 commit f1a2829

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

valid-parentheses/limlimjo.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ var isValid = function (s) {
1515
if (brackets[i]) {
1616
stack.push(brackets[i]);
1717
// 닫는 괄호일 경우
18-
} else if (i !== stack.pop()) {
18+
} else if (stack.length === 0 || i !== stack.pop()) {
1919
return false;
2020
}
2121
}
22-
return true;
22+
return stack.length === 0;
2323
};
2424

2525
// 시간복잡도: O(n)

0 commit comments

Comments
 (0)