Leetcode_10
2016-09-11 16:42
267 查看
bool isMatch(char* s, char* p) {
int m = strlen(s);
int n= strlen(p);
bool f[m+1][n+1];
f[0][0] = true;//{} matches {}
f[0][1] = false;//{} matches nothing if p's length is 1
int i,j;
//initialize the i=0 and j=0 of the matrix of the dynamic programming
for(i = 1;i <= m;i++){
f[i][0] = false;
}
for(j = 2;j <= n;j++){
f[0][j] = ( '*'==p[j-1] && f[0][j-2] );
}
for(i = 1;i <= m;i++){
for(j = 1;j <= n;j++){
if(p[j-1] != '*'){
f[i][j] = ( f[i-1][j-1] && (s[i-1] == p[j-1] || '.' == p[j-1]) );
}
else{
f[i][j] = f[i][j-2] || ( s[i-1] == p[j-2] || '.' == p[j-2]) && f[i-1][j];
}
}
}
return f[m]
;
}
相关文章推荐
- Java [leetcode 10] Regular Expression Matching
- Leetcode(10)Regular Expression Matching
- leetcode 刷题之路 10 Same Tree
- leetcode解题报告:10 Regular Expression Matching
- LeetCode_OJ【10】Regular Expression Matching
- LeetCode----10**. Regular Expression Matching
- leetcode 10 Regular Expression Matching
- leetcode 10 Regular Expression Matching
- [week 10][Leetcode][Dynamic Programming] Climbing Stairs
- leetcode-10-Regular Expression Matching
- leetcode 21:Merge Two Sorted Lists(15-10-9)
- LeetCode 10 Regular Expression Matching
- leetcode经典编程题(10)
- LeetCode 10: Regular Expression Match
- [leetcode]88. Merge Sorted Array[facebook](10)
- leetcode_10
- leetcode 10: Regular Expression Matching
- 面试笔试杂项积累-leetcode 6-10
- [LeetCode] Valid Palindrome [10]
- leetcode题解c++ | 10. Regular Expression Matching