Skip to content

Commit e55504c

Browse files
author
yeyounging
committed
Sync from source: 09db4bd2d4534c2b447007eebc7a003bcc5c94be
1 parent ed6d47b commit e55504c

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

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

0 commit comments

Comments
 (0)