Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class RowAndManyCoins {
- public String getWinner(String cells) {
- int A = 0;
- int B = 0;
- boolean isAfirst = ( cells.charAt(0) == 'A' );
- if ( isAfirst ) A++;
- else B++;
- for ( int i = 1 ; i < cells.length() ; i++ ) {
- if ( isAfirst )
- if ( cells.charAt(i) != 'A' ) {
- B++;
- isAfirst = false;
- }
- if ( !isAfirst )
- if ( cells.charAt(i) != 'B' ) {
- A++;
- isAfirst = true;
- }
- }
- if ( A >= B ) return "Alice";
- return "Bob";
- }
- }
Add Comment
Please, Sign In to add comment