Problem Statement
Return the smallest non-negative integer that can be added to originalNumber such that the resulting integer contains at least one digit k. All numbers should have no extra leading zeroes.
Definition
- Class:
- ObtainingDigitK
- Method:
- minNumberToAdd
- Parameters:
- String, int
- Returns:
- int
- Method signature:
- int minNumberToAdd(String originalNumber, int k)
- (be sure your method is public)
Constraints
- originalNumber will contain between 1 and 50 characters, inclusive.
- originalNumber will contain only digits ('0'-'9').
- originalNumber will represent a non-negative integer with no extra leading zeroes.
- k will be between 0 and 9, inclusive.
Examples
"153"
7
Returns: 4
153 + 4 = 157"158"
7
Returns: 9
158 + 9 = 167"7853192"
2
Returns: 0
Digit '2' is already present in the number."99999999999999999999999999999999999999999999999"
0
Returns: 1
Add 1 to get a lot of zeroes.