leecode 10 Regular Expression Matching
来源:互联网 发布:护士幻灯片制作软件 编辑:程序博客网 时间:2024/05/22 09:14
class Solution {public: bool isMatch(string s, string p) { int ls = s.length(); int lp = p.length(); bool mark[ls+1][lp+1]; memset(mark,0,sizeof(mark)); mark[0][0] = 1; for(int i = 1; i < lp && p[i] == '*'; i+=2){ mark[0][i+1] = 1; } for(int i = 1; i <= ls; ++i){ for(int j = 1; j <= lp; ++j){ if(p[j-1] == '.' || p[j-1] == s[i -1]) mark[i][j] = mark[i-1][j-1]; else if(j > 1 && p[j-1] == '*') mark[i][j] = mark[i][j-2] || (mark[i-1][j] && (p[j-2] == '.' || s[i-1] == p[j-2])); // .* } } return mark[ls][lp]; }};
public boolean isMatch(String s, String p) {
boolean[] match = new boolean[s.length()+1];
Arrays.fill(match, false);
match[s.length()] = true;
for(int i=p.length()-1;i>=0;i--){
if(p.charAt(i)=='*'){
for(int j=s.length()-1;j>=0;j--) match[j] = match[j]||match[j+1]&&(p.charAt(i-1)=='.'||s.charAt(j)==p.charAt(i-1));
i--;
}
else{
for(int j=0;j<s.length();j++) match[j] = match[j+1]&&(p.charAt(i)=='.'||p.charAt(i)==s.charAt(j));
match[s.length()] = false;
}
}
return match[0];
}
0 0
- leecode 10 Regular Expression Matching
- 10、Regular Expression Matching
- 10,Regular Expression Matching
- 10Regular Expression Matching
- 10 Regular Expression Matching
- 10、Regular Expression Matching
- 10Regular Expression Matching
- 【10】Regular Expression Matching
- 10-Regular Expression Matching
- Leetcode【10】:Regular Expression Matching
- [leetcode 10] Regular Expression Matching
- LeetCode(10) Regular Expression Matching
- [leetcode 10] Regular Expression Matching
- leetcode.10------------Regular Expression Matching
- [leetcode] 10 Regular Expression Matching
- [leetcode] 10 Regular Expression Matching
- LeetCode 10:《Regular Expression Matching》
- leetcode 10: Regular Expression Matching
- hdu 2063 过山车 二分图的最大匹配模板。。感觉模板代码很简洁
- 第三章第30题杨辉三角(图)20150427
- 【转】【UNITY3D 游戏开发之七】C# 中的委托、事件、匿名函数、Lambda 表达式
- 计算机网络 面试总结2
- select、poll、epoll
- leecode 10 Regular Expression Matching
- solr配置
- Android Service 服务(二)—— BroadcastReceiver
- failed to load the jni shared library
- zendframework 从apache下迁移到nginx下
- Java SE 基础概述(二)异常处理
- Android Service 服务(三)—— bindService与remoteService
- BLE 数据传输的一些名词
- 第五题