1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-10-18 06:42:08 +02:00

java: add «2938. Separate Black and White Balls»

URL:	https://leetcode.com/problems/separate-black-and-white-balls/
Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
Matej Focko 2024-10-15 21:49:19 +02:00
parent ac642f72d7
commit d7ed4d9aeb
Signed by: mfocko
SSH key fingerprint: SHA256:icm0fIOSJUpy5+1x23sfr+hLtF9UhY8VpMC7H4WFJP8

View file

@ -0,0 +1,19 @@
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;
}
}