Given a non-negative integer N, find the largest number that is less than or equal to N with monotone increasing digits.
(Recall that an integer has monotone increasing digits if and only if each pair of adjacent digits x and y satisfy x <= y.)
Example 1:
1 | Input: N = 10 |
Example 2:
1 | Input: N = 1234 |
Example 3:
1 | Input: N = 332 |
Note: N is an integer in the range [0, 10^9].
比较笨的办法,从N开始,一个一个的判断,直到找到符合要求的数。但其中有很多判断是多余的,可以做一些优化,减少判断的次数。比如当检测332不符合要求,则331、330都是没必要去判断的。
1 | class Solution { |