mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 00:43:04 +08:00
0738.单调递增的数字.md
This commit is contained in:
@ -163,7 +163,30 @@ class Solution:
|
|||||||
|
|
||||||
Go:
|
Go:
|
||||||
|
|
||||||
|
Javascript:
|
||||||
|
```Javascript
|
||||||
|
var monotoneIncreasingDigits = function(n) {
|
||||||
|
n = n.toString()
|
||||||
|
n = n.split('').map(item => {
|
||||||
|
return +item
|
||||||
|
})
|
||||||
|
let flag = Infinity
|
||||||
|
for(let i = n.length - 1; i > 0; i--) {
|
||||||
|
if(n [i - 1] > n[i]) {
|
||||||
|
flag = i
|
||||||
|
n[i - 1] = n[i - 1] - 1
|
||||||
|
n[i] = 9
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(let i = flag; i < n.length; i++) {
|
||||||
|
n[i] = 9
|
||||||
|
}
|
||||||
|
|
||||||
|
n = n.join('')
|
||||||
|
return +n
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
-----------------------
|
-----------------------
|
||||||
|
Reference in New Issue
Block a user