由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - Wildcard Matching 和 Regular Expression Matching 区别是什么
相关主题
Leetcode-010: Regular Expression Match (DP Solution)面试遇到了Regular Expression Matching时间复杂度是多少?
问一道LeeCode题目: regular expression matchingleetcode regular expression match的问题
如果面试遇到 regular expression match 或者 wildcard matching之类的regular expression mathinc --Java写竟然超时了/。
问一道Leetcode的题目。Wildcard Matching题求助
关于wildcard match和regex match的一个问题java没有指针真麻烦
leetcode 上面的Regular Expression MatchingisMatch("ab", ".*") → true 为什么是true???
Regular Expression Matching 问题请教。。Leetcode Timeout
Regular expression matching 在什么输入下时间复杂度是O(2^n)?问一下 leetcode里面的 regular expression matching
相关话题的讨论汇总
话题: dp话题: matching话题: regular话题: expression话题: int
进入JobHunting版参与讨论
1 (共1页)
y***n
发帖数: 1594
1
这两个题看这和像。
Wildcard Matching
'*' Matches any sequence of characters (including the empty sequence).
Regular Expression
'*' Matches zero or more of the preceding element.
高手指点一下。
p*****2
发帖数: 21240
2
dp
p*****3
发帖数: 488
3
低手可以不...
public class Solution {
public boolean isMatch(String s, String p) {
if (s == null || p == null)
return false;

int ls = s.length();
int lp = p.length();
boolean[][] dp = new boolean[ls+1][lp+1];
dp[0][0] = true;

for (int i = 1; i <= p.length(); i++) {
dp[0][i] = (p.charAt(i-1) == '*' ? dp[0][i-2] : false);
}

for (int i = 1; i <= ls; i++) {
for (int j = 1; j <= lp; j++) {
if (p.charAt(j-1) != '*' || j == 1) {
dp[i][j] = (p.charAt(j-1) == s.charAt(i-1) || p.charAt(j
-1) == '.') && dp[i-1][j-1];
}
else {
int it = i;
while (!dp[i][j] && it >= 1 && (s.charAt(it-1) == p.
charAt(j-2) || '.' == p.charAt(j-2))) {
if (dp[it-1][j-2])
dp[i][j] = true;
it--;
}

if (!dp[i][j])
dp[i][j] = dp[i][j-2];
}
}
}

return dp[ls][lp];
}
}
y***n
发帖数: 1594
4
这个是Regular Expression
1 (共1页)
进入JobHunting版参与讨论
相关主题
问一下 leetcode里面的 regular expression matching关于wildcard match和regex match的一个问题
已经用了dp,我的wildcard怎么还是过不了大ojleetcode 上面的Regular Expression Matching
leetcode里最弄不明白的两道题Regular Expression Matching 问题请教。。
regular expression match的greedy解法Regular expression matching 在什么输入下时间复杂度是O(2^n)?
Leetcode-010: Regular Expression Match (DP Solution)面试遇到了Regular Expression Matching时间复杂度是多少?
问一道LeeCode题目: regular expression matchingleetcode regular expression match的问题
如果面试遇到 regular expression match 或者 wildcard matching之类的regular expression mathinc --Java写竟然超时了/。
问一道Leetcode的题目。Wildcard Matching题求助
相关话题的讨论汇总
话题: dp话题: matching话题: regular话题: expression话题: int