Skip to content

Commit 8379aba

Browse files
author
Kyle Maune
committed
added second solution for bracket matcher
1 parent ac1e3a8 commit 8379aba

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Medium Difficulty/bracketMatcher2.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
function BracketMatcher(str) {
2+
3+
str.split("");
4+
var total1 = [], total2 = [], total3 = [], total4 = [];
5+
for(var i = 0; i < str.length; i++) {
6+
if(str[i] === "(") {
7+
total1.push(i);
8+
}
9+
if(str[i] === ")") {
10+
total2.push(i);
11+
}
12+
if(str[i] === "]") {
13+
total3.push(i);
14+
}
15+
16+
if(str[i] === "[") {
17+
total4.push(i);
18+
19+
}
20+
}
21+
var num = total1.length +total3.length;
22+
if(total1.length != total2.length || total3.length != total4.length ) {
23+
return 0;
24+
}
25+
else {
26+
return 1;
27+
}
28+
29+
}

0 commit comments

Comments
 (0)