#738

Monotone Increasing Digits

specialist · 885 · lc medium +31 · verified · 49.4% accepted · 1,406 likes · top 36%

Description

A positive integer has monotone increasing digits when every pair of consecutive digits satisfies x <= y. Given an integer n, find and return the largest integer that is at most n and whose digits are monotone increasing.

Example 1:

Input: n = 10
Output: 9

Example 2:

Input: n = 1234
Output: 1234

Example 3:

Input: n = 332
Output: 299

Code

1
2
3