LeetCode(力扣)738. 单调递增的数字Python

LeetCode738. 单调递增的数字

题目链接

https://leetcode.cn/problems/monotone-increasing-digits/description/

代码

python 复制代码
class Solution:
    def monotoneIncreasingDigits(self, n: int) -> int:
        strNum = str(n)
        flag = len(strNum)

        for i in range(len(strNum) - 1, 0, -1):
            if strNum[i] < strNum[i - 1]:
                flag = i
                strNum = strNum[:i - 1] + str(int(strNum[i - 1]) - 1) + strNum[i:]

        for i in range(flag, len(strNum)):
            strNum = strNum[:i] + '9' + strNum[i + 1:]

        return int(strNum)
相关推荐
垆边人似月.19 分钟前
华为题:敏感词替换
算法
0+11127 分钟前
算法 --哈希表
数据结构·算法·散列表
前端 贾公子1 小时前
LangGraph == 图的状态(State)管理 (中)
开发语言·数据库·python
Interview Aid1121 小时前
Stripe VO 面经汇总:5 轮面试题目与考察重点
算法
EEET智选1 小时前
科技晨间速报 | AI 安全警钟、开源新模型与苹果智能家居
人工智能·科技·算法·机器学习·ai
挖掘狂人1 小时前
哈希算法:一根看不见的 "指纹",如何撑起整个互联网
算法·程序员·掘金技术征文
the局外人1 小时前
FastAPI中jwt的基本使用与实践
后端·python·fastapi
鶴哥只手遮天1 小时前
ecRad 1.5.0 算法原理详解
算法·开源
mklpo1472 小时前
为不支持sse4.2命令集的老旧设备制作Win11 26H2系统镜像,2026-10-11。
运维·windows·python
GoldenSpider.AI2 小时前
用 AI 改流程之前先做「四桶」体检:9 次返工里 8 次靠规则就能消掉(附 Python 发布前校验器)
人工智能·python·自动化·ai智能体