Skip to content

Commit 2a8c017

Browse files
authored
Update 1963-minimum-number-of-swaps-to-make-the-string-balanced.js
1 parent 567ce7f commit 2a8c017

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

1963-minimum-number-of-swaps-to-make-the-string-balanced.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
/**
2+
* @param {string} s
3+
* @return {number}
4+
*/
5+
const minSwaps = function(s) {
6+
const stk = []
7+
for (let e of s) {
8+
if(e === '[') stk.push(e)
9+
else {
10+
if(stk.length) {
11+
stk.pop()
12+
} else stk.push(e)
13+
}
14+
}
15+
return Math.ceil(stk.length / 2)
16+
};
17+
18+
// another
19+
120
/**
221
* @param {string} s
322
* @return {number}

0 commit comments

Comments
 (0)