Skip to content

Commit c823a0f

Browse files
authored
Create 1769-minimum-number-of-operations-to-move-all-balls-to-each-box.js
1 parent c584af6 commit c823a0f

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @param {string} boxes
3+
* @return {number[]}
4+
*/
5+
const minOperations = function(boxes) {
6+
const res = []
7+
for(let i = 0, len = boxes.length; i < len; i++) {
8+
res[i] = helper(boxes, i)
9+
}
10+
11+
return res
12+
};
13+
14+
function helper(str, idx) {
15+
let res = 0
16+
for(let i = 0, len = str.length; i < len; i++) {
17+
if(i === idx || str[i] === '0') continue
18+
res += Math.abs(i - idx)
19+
}
20+
return res
21+
}

0 commit comments

Comments
 (0)