From 85821d01832942442db0456d50b0e505a0498f4c Mon Sep 17 00:00:00 2001 From: CyC2018 Date: Fri, 30 Oct 2026 20:18:04 +0800 Subject: [PATCH] =?UTF-8?q?Update=2046.=20=E6=8A=8A=E6=95=B0=E5=AD=97?= =?UTF-8?q?=E7=BF=BB=E8=AF=91=E6=88=90=E5=AD=97=E7=AC=A6=E4=B8=B2.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 补充动态规划状态定义与递推示例,补充原书及力扣题目的数字映射范围说明。 --- notes/46. 把数字翻译成字符串.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/notes/46. 把数字翻译成字符串.md b/notes/46. 把数字翻译成字符串.md index fcbd92fe..22eb7322 100644 --- a/notes/46. 把数字翻译成字符串.md +++ b/notes/46. 把数字翻译成字符串.md @@ -8,6 +8,10 @@ ## 解题思路 +dp[i] 表示前 i 位数字的翻译方法数。最后一位单独翻译(不为 0)时,方法数为 dp[i - 1];最后两位合起来翻译(10~26)时,方法数为 dp[i - 2]。两者相加就是 dp[i]。例如 12258 的 dp[0]~dp[5] 依次为 1, 1, 2, 3, 5, 5:最后的 58 大于 26,不能合起来翻译,所以 dp[5] = dp[4]。 + +原书和力扣 LCR 165 规定 0~25 对应 a~z,输入为整数:这时 0 也可以单独翻译,两位数的范围改为 10~25,递推方式不变。 + ```java public int numDecodings(String s) { if (s == null || s.length() == 0)