Skip to content

Commit fac6b9e

Browse files
Merge pull request #2153 from CodingTestStudy2/정진영
[정진영] 2026/10/09
2 parents a8a84fb + e365c40 commit fac6b9e

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @param {string} s
3+
* @return {boolean}
4+
*/
5+
var isValid = function(s) {
6+
const arr = [];
7+
8+
for (let i = 0; i<s.length; i++){
9+
if(s[i] == '(' || s[i] == '{' || s[i] == '['){
10+
arr.push(s[i]);
11+
} else {
12+
if (s[i] == ')' && arr[arr.length-1] !== '('){
13+
return false;
14+
} else if (s[i] == '}' && arr[arr.length-1] !== '{'){
15+
return false;
16+
} else if (s[i] == ']' && arr[arr.length-1] !== '['){
17+
return false;
18+
}
19+
arr.pop();
20+
}
21+
}
22+
23+
return arr.length == 0;
24+
};
25+

0 commit comments

Comments
 (0)