由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - Leetcode-010: Regular Expression Match (DP Solution)
相关主题
Wildcard Matching 和 Regular Expression Matching 区别是什么leetcode 一道题 valid palindrome
Leetcode Timeout帮忙看道题:[leetcode] word break
regular expression mathinc --Java写竟然超时了/。leetcode是不是最近有点问题?
Interleave Strings那个题目有O(n)时间 O(1)空间算法么?leetcode 上面的Regular Expression Matching
问一道Leetcode的题目。问一下 leetcode里面的 regular expression matching
问一道LeeCode题目: regular expression matchingRegular Expression Matching 问题请教。。
java没有指针真麻烦leetcode valid number
interleave string 的题目关于 unique paths,总是过不了 OJ, 请牛牛们帮忙看看~~~先谢过。。。
相关话题的讨论汇总
话题: match话题: int话题: solution话题: boolean话题: string
进入JobHunting版参与讨论
1 (共1页)
b********g
发帖数: 28
1
public class Solution {
public boolean isMatch(String s, String p) {
// Start typing your Java solution below
// DO NOT write main() function
if(s == null || p == null) return false;
int m = s.length(), n = p.length();
boolean[][] match = new boolean[m + 1][n + 1];
match[0][0] = true;
for(int i = 1; i <= m; i++){
match[i][0] = false;
}
for(int j = 1; j <= n; j++){
if(p.charAt(j - 1) == '*'){
match[0][j] = match[0][j - 2];
}else{
match[0][j] = false;
}
}

for(int i = 1; i <= m; i++){
for(int j = 1; j <= n; j++){
if(p.charAt(j - 1) == '*'){
match[i][j] |= match[i][j - 2];
if(s.charAt(i - 1) == p.charAt(j - 2) || p.charAt(j - 2)
== '.'){
match[i][j] |= match[i - 1][j];
}
}else{
match[i][j] = ((s.charAt(i - 1) == p.charAt(j - 1) || p.
charAt(j - 1) == '.') && match[i - 1][j - 1]);
}
}
}

return match[m][n];
}
}
1 (共1页)
进入JobHunting版参与讨论
相关主题
关于 unique paths,总是过不了 OJ, 请牛牛们帮忙看看~~~先谢过。。。问一道Leetcode的题目。
请问大牛们关于Regular expression matching问一道LeeCode题目: regular expression matching
搞了小半个月,leetcode还有20题java没有指针真麻烦
贡献今天facebook电面 一道题interleave string 的题目
Wildcard Matching 和 Regular Expression Matching 区别是什么leetcode 一道题 valid palindrome
Leetcode Timeout帮忙看道题:[leetcode] word break
regular expression mathinc --Java写竟然超时了/。leetcode是不是最近有点问题?
Interleave Strings那个题目有O(n)时间 O(1)空间算法么?leetcode 上面的Regular Expression Matching
相关话题的讨论汇总
话题: match话题: int话题: solution话题: boolean话题: string