We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f6cf44e commit 6e0e5b3Copy full SHA for 6e0e5b3
valid-parentheses/whewchews.ts
@@ -7,7 +7,6 @@
7
* 위의 두 경우에 해당되지 않으면 return true
8
*/
9
function isValid(s: string): boolean {
10
- const charSet = new Set(["(", "{", "["]);
11
const openCharStack = [];
12
const CHAR_PAIR = {
13
"]": "[",
@@ -17,17 +16,15 @@ function isValid(s: string): boolean {
17
16
18
for (let i = 0; i <= s.length - 1; i++) {
19
const char = s[i];
20
- if (charSet.has(char)) {
21
- openCharStack.push(char);
22
- continue;
23
- }
24
25
if (char in CHAR_PAIR) {
26
const pair = CHAR_PAIR[char];
27
const lastOpenChar = openCharStack.pop();
28
if (lastOpenChar !== pair) {
29
return false;
30
}
+ } else {
+ openCharStack.push(char);
31
32
33
0 commit comments