1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| class Solution { public long minimumSteps(String s) { long steps = 0;
int oneCount = 0; for (int i = 0; i < s.length(); i++) { if (s.charAt(i) == '1') { oneCount++; } else { steps += oneCount; } }
return steps; } }
|
References
2938. Separate Black and White Balls