import java.util.*;
import java.math.*;
//rename the class name before submitting
public class BlackAndWhiteSolitaire {
public static void main(String[] args) {
BlackAndWhiteSolitaire obj = new BlackAndWhiteSolitaire();
System.out.println(
obj.minimumTurns(
"BW"
));
}
public int minimumTurns(String cardFront) {
int nbfirst = 0;
int nwfirst = 0;
for (int i = 0; i < cardFront.length(); i++) {
if (i % 2 == 0) {
if (cardFront.charAt(i) == 'B')
nwfirst++;
else
nbfirst++;
}
else {
if (cardFront.charAt(i) == 'B')
nbfirst++;
else
nwfirst++;
}
}
return Math.min(nwfirst, nbfirst);
}
}
No comments:
Post a Comment