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.
1
Returns: 203456789
2
Returns: 103456789
3
Returns: 102456789
4
Returns: 102356789
5
Returns: 102346789
6
Returns: 102345789
7
Returns: 102345689
8
Returns: 102345679
9
Returns: 102345678
10
Returns: 23456789
11
Returns: 203456789
12
Returns: 30456789
333333333
Returns: 102456789
123456789
Returns: 0
234567890
Returns: 1
134567890
Returns: 2
124567890
Returns: 3
123567890
Returns: 4
123467890
Returns: 5
123457890
Returns: 6
123456890
Returns: 7
123456790
Returns: 8
123456780
Returns: 9
900000000
Returns: 12345678
123456781
Returns: 90
222444666
Returns: 1035789
222000777
Returns: 1345689
913285476
Returns: 0
913280476
Returns: 5
913282476
Returns: 50
1456789
Returns: 203
2345
Returns: 106789