Monotone Increasing Digits
An integer has monotone increasing digits if and only if each pair of adjacent digits x and y satisfy x <= y.
Given an integer n, return the largest number that is less than or equal to n with monotone increasing digits.
Example 1
Input
n = 10Output
9The largest number less than or equal to 10 with monotone increasing digits is 9.
Example 2
Input
n = 1234Output
1234The digits of 1234 are already monotone increasing, so the answer is 1234.
Constraints
- 0 <= n <= 10^9