Problem Statement (250)
????
Given a positive integer n. you can modify any digit in the N decimal representation to get the number in another decimal representation, the new number you get after modification must be strictly less than N (this new number can have some leading 0 ). return the maximum number after modification as required.
Definition
????
Class:
Changedigit
Method:
Change
Parameters:
Int
Returns:
Int
Method signature:
Int change (int n)
(Be sure your method is public)
????
Constraints
-
N is a positive integer between 1 and 1,000,000,000.
Examples
0)
????
123
Returns: 122
After modifying one of them, we can get the following numbers less than N: 023,103,113,120,121, and 122. The maximum number is 122.
1)
????
94040
Returns: 94030
2)
????
999999999
Returns: 999999998
3)
????
1000000000
Returns: 0
In this example, we only have one solution, replacing the first '1' with '0' to get "0000000000 ", this is a decimal value of 0 (with 9 leading zeros ).
4)
????
4321000
Returns: 4320000
Public class first {
Public static void main (string [] ARGs ){
First F = new first ();
System. Out. println (F. Change (999999999 ));
}
Public int change (int n ){
Int bit = 0;
Int P = 10;
Int temp = N;
While (true ){
If (TEMP % 10! = 0 ){
Return N-(P/10 );
}
Temp/= 10;
P * = 10;
}
}
}