Skip to content

Commit 6e0e5b3

Browse files
whewchewsobzva
andauthored
refactor: remove charSet
Co-authored-by: Dongyeong Chon <[email protected]>
1 parent f6cf44e commit 6e0e5b3

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

valid-parentheses/whewchews.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
* 위의 두 경우에 해당되지 않으면 return true
88
*/
99
function isValid(s: string): boolean {
10-
const charSet = new Set(["(", "{", "["]);
1110
const openCharStack = [];
1211
const CHAR_PAIR = {
1312
"]": "[",
@@ -17,17 +16,15 @@ function isValid(s: string): boolean {
1716

1817
for (let i = 0; i <= s.length - 1; i++) {
1918
const char = s[i];
20-
if (charSet.has(char)) {
21-
openCharStack.push(char);
22-
continue;
23-
}
2419

2520
if (char in CHAR_PAIR) {
2621
const pair = CHAR_PAIR[char];
2722
const lastOpenChar = openCharStack.pop();
2823
if (lastOpenChar !== pair) {
2924
return false;
3025
}
26+
} else {
27+
openCharStack.push(char);
3128
}
3229
}
3330

0 commit comments

Comments
 (0)