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:
parent
ac642f72d7
commit
d7ed4d9aeb
1 changed files with 19 additions and 0 deletions
19
java/separate-black-and-white-balls.java
Normal file
19
java/separate-black-and-white-balls.java
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue