From dcd2f82501bbeb38360e7120a0dcd6e526676ccd Mon Sep 17 00:00:00 2001 From: CyC2018 Date: Wed, 28 Oct 2026 13:45:03 +0800 Subject: [PATCH] =?UTF-8?q?Update=2019.=20=E6=AD=A3=E5=88=99=E8=A1=A8?= =?UTF-8?q?=E8=BE=BE=E5=BC=8F=E5=8C=B9=E9=85=8D.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 题目链接改为力扣中的对应题目,题目描述和代码按该题的接口调整。 --- notes/19. 正则表达式匹配.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/notes/19. 正则表达式匹配.md b/notes/19. 正则表达式匹配.md index a0ad0053..cb722e96 100644 --- a/notes/19. 正则表达式匹配.md +++ b/notes/19. 正则表达式匹配.md @@ -1,6 +1,6 @@ # 19. 正则表达式匹配 -[牛客网](https://www.nowcoder.com/practice/28970c15befb4ff3a264189087b99ad4?tpId=13&tqId=11205&tab=answerKey&from=cyc_github) +[Leetcode](https://leetcode.cn/problems/zheng-ze-biao-da-shi-pi-pei-lcof/) ## 题目描述 @@ -13,22 +13,22 @@ 应该注意到,'.' 是用来当做一个任意字符,而 '\*' 是用来重复前面的字符。这两个的作用不同,不能把 '.' 的作用和 '\*' 进行类比,从而把它当成重复前面字符一次。 ```java -public boolean match(String str, String pattern) { +public boolean articleMatch(String s, String p) { - int m = str.length(), n = pattern.length(); + int m = s.length(), n = p.length(); boolean[][] dp = new boolean[m + 1][n + 1]; dp[0][0] = true; for (int i = 1; i <= n; i++) - if (pattern.charAt(i - 1) == '*') + if (p.charAt(i - 1) == '*') dp[0][i] = dp[0][i - 2]; for (int i = 1; i <= m; i++) for (int j = 1; j <= n; j++) - if (str.charAt(i - 1) == pattern.charAt(j - 1) || pattern.charAt(j - 1) == '.') + if (s.charAt(i - 1) == p.charAt(j - 1) || p.charAt(j - 1) == '.') dp[i][j] = dp[i - 1][j - 1]; - else if (pattern.charAt(j - 1) == '*') - if (pattern.charAt(j - 2) == str.charAt(i - 1) || pattern.charAt(j - 2) == '.') { + else if (p.charAt(j - 1) == '*') + if (p.charAt(j - 2) == s.charAt(i - 1) || p.charAt(j - 2) == '.') { dp[i][j] |= dp[i][j - 1]; // a* counts as single a dp[i][j] |= dp[i - 1][j]; // a* counts as multiple a dp[i][j] |= dp[i][j - 2]; // a* counts as empty