Ad
  • Custom User Avatar

    very clear appart from streams which I don't use yet, however you can remove the "else" after the return statement :

            for (int i = 0; i < 3; i++) {
                if (board[i][0] == board[i][1] && board[i][1] == board[i][2] && board[i][0] > 0) return board[i][0];
                if (board[0][i] == board[1][i] && board[1][i] == board[2][i] && board[0][i] > 0) return board[0][i];
                if ((board[1][1] == board[0][0] && board[0][0] == board[2][2] && board[1][1] > 0)
                  || board[1][1] == board[2][0] && board[2][0] == board[0][2] && board[1][1] > 0) return board[1][1];
            }
            if (Arrays.stream(board).flatMapToInt(Arrays::stream).anyMatch(n -> n == 0)) return -1;
            return 0;
      }
    
    
  • Custom User Avatar

    dude I never thought of importing java.lang.Object

  • Custom User Avatar

    The Integer class already converts decimal to hex string. However if it didn't, I suggest you use switch(decimalDigit)

  • Custom User Avatar

    Now that multiplyDigits method is nice, I used to make a char[] and loop it...
    Here is your compacted code :

    		return(n>9)?persistence(multiplyDigits(n))+1:0;
    	}
      public static long multiplyDigits(long n) {
        return (n>9)?n%10*multiplyDigits(n/10):n;
      }```
    
  • Custom User Avatar

    Completely forgot you could multiply i in a for loop, this is the upgraded version of mine