Guest User

Untitled

a guest
Feb 19th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. public class RowAndManyCoins {
  2.  
  3. public String getWinner(String cells) {
  4. int A = 0;
  5. int B = 0;
  6. boolean isAfirst = ( cells.charAt(0) == 'A' );
  7. if ( isAfirst ) A++;
  8. else B++;
  9.  
  10. for ( int i = 1 ; i < cells.length() ; i++ ) {
  11. if ( isAfirst )
  12. if ( cells.charAt(i) != 'A' ) {
  13. B++;
  14. isAfirst = false;
  15. }
  16. if ( !isAfirst )
  17. if ( cells.charAt(i) != 'B' ) {
  18. A++;
  19. isAfirst = true;
  20. }
  21. }
  22.  
  23.  
  24. if ( A >= B ) return "Alice";
  25. return "Bob";
  26. }
  27.  
  28. }
Add Comment
Please, Sign In to add comment