mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2026-02-02 18:39:09 +08:00
Update
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
<p align="center"><strong><a href="https://mp.weixin.qq.com/s/tqCxrMEU-ajQumL1i8im9A">参与本项目</a>,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!</strong></p>
|
||||
|
||||
|
||||
## 738.单调递增的数字
|
||||
# 738.单调递增的数字
|
||||
[力扣题目链接](https://leetcode-cn.com/problems/monotone-increasing-digits/)
|
||||
|
||||
给定一个非负整数 N,找出小于或等于 N 的最大的整数,同时这个整数需要满足其各个位数上的数字是单调递增。
|
||||
@@ -13,16 +13,16 @@
|
||||
(当且仅当每个相邻位数上的数字 x 和 y 满足 x <= y 时,我们称这个整数是单调递增的。)
|
||||
|
||||
示例 1:
|
||||
输入: N = 10
|
||||
输出: 9
|
||||
* 输入: N = 10
|
||||
* 输出: 9
|
||||
|
||||
示例 2:
|
||||
输入: N = 1234
|
||||
输出: 1234
|
||||
* 输入: N = 1234
|
||||
* 输出: 1234
|
||||
|
||||
示例 3:
|
||||
输入: N = 332
|
||||
输出: 299
|
||||
* 输入: N = 332
|
||||
* 输出: 299
|
||||
|
||||
说明: N 是在 [0, 10^9] 范围内的一个整数。
|
||||
|
||||
@@ -123,7 +123,7 @@ public:
|
||||
## 其他语言版本
|
||||
|
||||
|
||||
Java:
|
||||
### Java:
|
||||
```java
|
||||
版本1
|
||||
class Solution {
|
||||
@@ -170,8 +170,8 @@ class Solution {
|
||||
```
|
||||
|
||||
|
||||
Python:
|
||||
```python3
|
||||
### Python:
|
||||
```python
|
||||
class Solution:
|
||||
def monotoneIncreasingDigits(self, n: int) -> int:
|
||||
a = list(str(n))
|
||||
@@ -182,7 +182,7 @@ class Solution:
|
||||
return int("".join(a))
|
||||
```
|
||||
|
||||
Go:
|
||||
### Go
|
||||
```golang
|
||||
func monotoneIncreasingDigits(N int) int {
|
||||
s := strconv.Itoa(N)//将数字转为字符串,方便使用下标
|
||||
@@ -203,7 +203,8 @@ func monotoneIncreasingDigits(N int) int {
|
||||
return res
|
||||
}
|
||||
```
|
||||
Javascript:
|
||||
|
||||
### Javascript
|
||||
```Javascript
|
||||
var monotoneIncreasingDigits = function(n) {
|
||||
n = n.toString()
|
||||
|
||||
Reference in New Issue
Block a user