Leetcode|Medium|Sequence|738. Monotonically increasing numbers

Insert picture description here

how are you

[Assessment knowledge] How to read each number from the tens to higher digits of any number

class Solution {
    
    
public:
    int monotoneIncreasingDigits(int N) {
    
    
        if (N < 10) return N;
        int k;
        // 从十位开始向更高位遍历
        for (k = 10; N / k > 0; k *= 10) {
    
    
            // 高位比低位数值大
            if (N / k % 10 > N / (k / 10) % 10) 
                N -= N % k + 1; 
        }
        return N;
    }
};

Insert picture description here

Guess you like

Origin blog.csdn.net/SL_World/article/details/114876941