44. Wildcard Matching
来源:互联网 发布:人工智能与机器人技术 编辑:程序博客网 时间:2024/05/22 14:38
动态规划
bool dp[100000];bool rp[100000];class Solution {public: bool isMatch(string s, string p) { int m=p.size(),n=s.size(); int i,j; memset(dp, 0, sizeof(dp)); memset(rp,0,sizeof(rp)); dp[0]=1; for(i=1;i<=m;i++) { if(p[i-1]=='*') rp[0]=dp[0]; for(j=1;j<=n;j++) { if(p[i-1]=='?') { if(dp[j-1]) rp[j]=true; } else if(p[i-1]=='*') { if(dp[j-1]||dp[j]||rp[j-1]) rp[j]=true; } else { if(dp[j-1]&&p[i-1]==s[j-1]) rp[j]=true; } } for(j=0;j<=n;j++) dp[j]=rp[j]; memset(rp,0,sizeof(rp)); } return dp[n]; }};
方法2:
迭代回溯
class Solution {public: bool isMatch(string s, string p) { int n=s.size(); int m=p.size(); int i=0,j=0,k=-1,t=-1; while(s[i]!='\0') { if(s[i]==p[j]||p[j]=='?') i++,j++; else if(p[j]=='*') t=i,k=j++; else if(k!=-1) { i=++t; j=k+1; } else return false; } while(j<m&&p[j]=='*') j++; return j>=m; }};
0 0
- LeetCode --- 44. Wildcard Matching
- [Leetcode] 44. Wildcard Matching
- 44. Wildcard Matching
- Leetcode 44. Wildcard Matching
- 44. Wildcard Matching
- 44. Wildcard Matching
- leetcode 44. Wildcard Matching
- Leetcode 44. Wildcard Matching
- Leetcode:44. Wildcard Matching
- LeetCode 44. Wildcard Matching
- leetcode.44. Wildcard Matching
- LeetCode 44. Wildcard Matching
- Leetcode-44. Wildcard Matching
- 44. Wildcard Matching
- 44. Wildcard Matching
- [LeetCode] 44. Wildcard Matching
- 44. Wildcard Matching
- [leetcode] 44. Wildcard Matching
- BLE(Bluetooth Low Energy)---first part
- 【Java数据结构与算法01】 | 第1章--综述(Java与C++区别)
- JSON数据简介
- 面试14:调整数组顺序使奇数位于偶数前面
- Release LIB is huge compared to debug
- 44. Wildcard Matching
- leetcode 44. Wildcard Matching
- 05.Spring 资源加载 - Resource
- 刮奖效果控件--ScratchView
- Markdown 编辑器语法指南
- halcon模板匹配学习(二) 准备模板
- Linux中的Shell类型检测
- 滤波算法
- Redis集群搭建