Problem Statement
A round of Blackjack has ended and it's time to reveal the winner. Use the following two rules to determine the outcome of the round:
- If a player has more than 21 points, he loses.
- Of all the players who have 21 or fewer points, the ones with the maximum number of points are the winners.
You are given a int[] points, where points[i] is the number of points received by the i-th player. If there is exactly one winner, return the 0-based index of the winning player. Otherwise, return -1.
Definition
- Class:
- SimpleCardGame
- Method:
- whoIsTheWinner
- Parameters:
- int[]
- Returns:
- int
- Method signature:
- int whoIsTheWinner(int[] points)
- (be sure your method is public)
Constraints
- points will contain between 1 and 50 elements, inclusive.
- Each element of points will be between 1 and 35, inclusive.
Examples
{1, 2}Returns: 1
Both players have 21 or fewer points. Among them, player 1 has the maximum number of points.{1, 2, 3, 3, 2}Returns: -1
Players 2 and 3 both have the maximum number of points, so we have 2 winners.{1, 22}Returns: 0
Player 1 has more than 21 points, so the winner is player 0.{21, 20, 19}Returns: 0
{22, 23, 22}Returns: -1
No winner here.{1, 2, 21, 3, 4, 21}Returns: -1
{31, 33, 4, 23, 3, 23, 12, 35, 17, 27, 14, 6}Returns: 8