Problem Statement
Several players play a game. Each player chooses a certain number, writes it down (in decimal notation, without leading zeroes)
and sorts the digits of the notation in non-decreasing order, obtaining another number.
The player who receives the largest number wins.
You are given a int[] numbers, the list of numbers inilially chosen by the players. Return the winner's resulting number.
You are given a int[] numbers, the list of numbers inilially chosen by the players. Return the winner's resulting number.
Definition
- Class:
- NumbersGame
- Method:
- winningNumber
- Parameters:
- int[]
- Returns:
- int
- Method signature:
- int winningNumber(int[] numbers)
- (be sure your method is public)
Constraints
- numbers will contain between 2 and 50 elements, inclusive.
- Each element of numbers will be between 0 and 100000, inclusive.
- All elements of numbers will be distinct.
Examples
{1,10,100,1000,10000,100000}Returns: 1
After sorting digits all numbers become equal.{2345,8756}Returns: 5678
{9638,8210,331}Returns: 3689