Problem Statement
Given is a non-negative integer X.
Construct and return the smallest non-negative integer Y such that (in base 10) each digit that does not appear in X does appear in Y.
Note that Y is not allowed to start with unnecessary leading zeros. (See Examples 2 and 3.)
Definition
- Class:
- SmallestOppositeNumber
- Method:
- construct
- Parameters:
- int
- Returns:
- int
- Method signature:
- int construct(int X)
- (be sure your method is public)
Notes
- The constraints guarantee that X has at most 9 digits. Thus, at least one of the digits 0-9 will be missing from X.
Constraints
- X will be between 0 and 999,999,999, inclusive.
Examples
2024868
Returns: 13579
The digits 0, 2, 4, 6 and 8 appear in the given number X. (Some of them appear more than once, but that does not matter.) The digits that do not appear in the given number X are the digits 1, 3, 5, 7 and 9. All these digits must therefore appear in Y. The smallest non-negative integer that contains these five digits is clearly Y = 13,579.0
Returns: 123456789
The number X = 0 contains the digit 0. The number Y must contain the digits 1-9. The smallest such Y is obviously 123,456,789.123456798
Returns: 0
This is almost an inverse of the previous example: X contains all digits other than 0, so Y should contain the digit 0. The smallest non-negative integer that contains the digit 0 is the number 0.45678
Returns: 10239
Remember that the number Y cannot start with an unnecessary leading zero. Thus, "01239" is not a valid answer. The smallest number that really contains the digits 0, 1, 2, 3, 9 is 10,239.