第八章 贪心算法 part06

738. 单调递增的数字

python 复制代码
class Solution:
    def monotoneIncreasingDigits(self, n: int) -> int:
        strNum = list(str(n))
        for i in range(len(strNum)-1,0,-1):
            if strNum[i] < strNum[i-1]:
                strNum[i-1] = str(int(strNum[i - 1]) - 1)
                strNum[i:] = '9' * (len(strNum) - i)
        return (int("".join(strNum)))
相关推荐
热爱生活的五柒13 小时前
深度聚类(Deep Clustering)与度量学习(Metric Learning)的共同点和不同点
人工智能·算法·机器学习
LYFlied1 天前
【每日算法】LeetCode 153. 寻找旋转排序数组中的最小值
数据结构·算法·leetcode·面试·职场和发展
唐装鼠1 天前
rust自动调用Deref(deepseek)
开发语言·算法·rust
ytttr8731 天前
MATLAB基于LDA的人脸识别算法实现(ORL数据库)
数据库·算法·matlab
jianfeng_zhu1 天前
整数数组匹配
数据结构·c++·算法
smj2302_796826521 天前
解决leetcode第3782题交替删除操作后最后剩下的整数
python·算法·leetcode
LYFlied1 天前
【每日算法】LeetCode 136. 只出现一次的数字
前端·算法·leetcode·面试·职场和发展
唯唯qwe-1 天前
Day23:动态规划 | 爬楼梯,不同路径,拆分
算法·leetcode·动态规划
做科研的周师兄1 天前
中国土壤有机质数据集
人工智能·算法·机器学习·分类·数据挖掘
来深圳1 天前
leetcode 739. 每日温度
java·算法·leetcode