Problem Statement
Create a class CommonDigits with a method digit that takes an int num and returns the single digit that occurs most often in the decimal representation of num (without leading zeros). If several digits occur the same number of times, give preference to the one whose leftmost (most significant) occurrence is farthest to the left.
Definition
- Class:
- CommonDigits
- Method:
- digit
- Parameters:
- int
- Returns:
- int
- Method signature:
- int digit(int num)
- (be sure your method is public)
Constraints
- num is between 1 and 1000000000, inclusive.
Examples
123
Returns: 1
All digits occur the same number of times so return the leftmost.102030
Returns: 0
79888799
Returns: 9