From 8973967dd10fbea86996f9df413aa1559c1dac53 Mon Sep 17 00:00:00 2001 From: ShuangmingMa <52561813+ShuangmingMa@users.noreply.github.com> Date: Sun, 8 Oct 2023 15:05:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=200392.=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E5=AD=90=E5=BA=8F=E5=88=97.md=20Go=E4=BA=8C=E7=BB=B4DP?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=EF=BC=8C=E5=B9=B6=E5=A2=9E=E5=8A=A0Go?= =?UTF-8?q?=E4=B8=80=E7=BB=B4DP=E8=A7=A3=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改 0392.判断子序列.md Go二维DP格式,并增加Go一维DP解法 --- problems/0392.判断子序列.md | 39 ++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/problems/0392.判断子序列.md b/problems/0392.判断子序列.md index 12d3fa48..cb9323c8 100644 --- a/problems/0392.判断子序列.md +++ b/problems/0392.判断子序列.md @@ -240,26 +240,45 @@ function isSubsequence(s: string, t: string): boolean { ### Go: +二维DP: + ```go func isSubsequence(s string, t string) bool { - dp := make([][]int,len(s)+1) - for i:=0;i= 1; j -- { + if t[i - 1] == s[j - 1] { + dp[j] = dp[j - 1] + 1 + } + } + } + return dp[len(s)] == len(s) +} +``` + + +### Rust: ```rust impl Solution {