Skip to content

Commit 0f0c811

Browse files
authored
Create 2938-separate-black-and-white-balls.js
1 parent 3340470 commit 0f0c811

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @param {string} s
3+
* @return {number}
4+
*/
5+
var minimumSteps = function(s) {
6+
let n = s.length
7+
let left = n - 1
8+
let right = n - 1
9+
let cnt = 0
10+
while (left >= 0) {
11+
if (s.charAt(left) === '1') {
12+
cnt += right - left
13+
right--
14+
}
15+
left--
16+
}
17+
return cnt
18+
};

0 commit comments

Comments
 (0)