题目简介
738. 单调递增的数字
当且仅当每个相邻位数上的数字 x 和 y 满足 x <= y 时,我们称这个整数是单调递增的。
给定一个整数 n ,返回 小于或等于 n 的最大数字,且数字呈 单调递增 。
968. 监控二叉树
给定一个二叉树,我们在树的节点上安装摄像头。
节点上的每个摄影头都可以监视其父对象、自身及其直接子对象。
计算监控树的所有节点所需的最小摄像头数量。
初见思路
- 最好理解的思路,不符合题意就减一位,加上以9结尾的最近一个数字的字符串。
class Solution:
def monotoneIncreasingDigits(self, N: int) -> int:
strNum = str(N)
for i in range(len(strNum) - 1, 0, -1):
if strNum[i - 1] > strNum[i]:
strNum = strNum[:i - 1] + str(int(strNum[i - 1]) - 1) + '9' * (len(strNum) - i)
return int(strNum)
968.这题的思路不是很清晰,思路待完善。先跳过,待后面仔细思考一下。
复盘思路
https://programmercarl.com/0738.%E5%8D%95%E8%B0%83%E9%80%92%E5%A2%9E%E7%9A%84%E6%95%B0%E5%AD%97.html
https://programmercarl.com/0968.%E7%9B%91%E6%8E%A7%E4%BA%8C%E5%8F%89%E6%A0%91.html