Matej Focko
d7ed4d9aeb
URL: https://leetcode.com/problems/separate-black-and-white-balls/ Signed-off-by: Matej Focko <me@mfocko.xyz>
19 lines
337 B
Java
19 lines
337 B
Java
class Solution {
|
|
public long minimumSteps(String s) {
|
|
long swaps = 0;
|
|
|
|
int blackBalls = 0;
|
|
for (int i = 0; i < s.length(); ++i) {
|
|
switch (s.charAt(i)) {
|
|
case '0':
|
|
swaps += blackBalls;
|
|
break;
|
|
case '1':
|
|
++blackBalls;
|
|
break;
|
|
}
|
|
}
|
|
|
|
return swaps;
|
|
}
|
|
}
|