Leetcode-Regular Expression Matching
来源:互联网 发布:c语言程序等腰三角形 编辑:程序博客网 时间:2024/06/07 17:56
Implement regular expression matching with support for ‘.’ and ‘*’.
‘.’ Matches any single character.
‘*’ Matches zero or more of the preceding element.
The matching should cover the entire input string (not partial).
The function prototype should be:
bool isMatch(const char *s, const char *p)
Some examples:
isMatch(“aa”,”a”) → false
isMatch(“aa”,”aa”) → true
isMatch(“aaa”,”aa”) → false
isMatch(“aa”, “a*”) → true
isMatch(“aa”, “.*”) → true
isMatch(“ab”, “.*”) → true
isMatch(“aab”, “c*a*b”) → true
DP
bool isMatch(string s, string p) { int sl=s.length(); int pl=p.length(); vector<vector<bool>> dp(pl+1,vector<bool>(sl+1,false)); dp[0][0]=true; for(int i=1;i<=pl;++i) { dp[i][0]=i-2>=0&&p[i-1]=='*'&&dp[i-2][0]; for(int j=1;j<=sl;++j) { if(p[i-1]==s[j-1]||p[i-1]=='.') { dp[i][j]=dp[i-1][j-1]; } else if(p[i-1]=='*'&&i-2>=0) { if(dp[i-2][j]||((p[i-2]==s[j-1]||p[i-2]=='.')&&dp[i][j-1])) { dp[i][j]=true; } else { dp[i][j]=false; } } else { dp[i][j]=false; } } } return dp[pl][sl]; }
0 0
- LeetCode: Regular Expression Matching
- LeetCode: Regular Expression Matching
- leetcode Regular Expression Matching
- [Leetcode] Regular Expression Matching
- [LeetCode]Regular Expression Matching
- LeetCode-Regular Expression Matching
- Regular Expression Matching LeetCode
- LeetCode | Regular Expression Matching
- LeetCode: Regular Expression Matching
- Leetcode: Regular Expression Matching
- [LeetCode] Regular Expression matching
- [LeetCode] Regular Expression Matching
- LeetCode Regular Expression Matching
- leetcode Regular Expression Matching
- leetcode: Regular Expression Matching
- LeetCode Regular Expression Matching
- Leetcode: Regular Expression Matching
- leetcode:Regular Expression Matching
- Matlab R2015a Win8.1 高分屏 高分辨率
- 08-nginx网站的配置过程记录
- Eclipse Scala IDE , run as -> Scala Application不见了
- 23. Merge k Sorted Lists
- GRE写作必备句型
- Leetcode-Regular Expression Matching
- PayPal高级工程总监:读完这100篇论文 就能成大数据高手
- Android Studio用法之---快捷键
- grep的用法
- org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document
- 哈佛为什么群星闪耀?
- C语言之基本算法13—兑换硬币
- reactjs 视频教程
- 学习android编程之路(2)— eclipse安卓开发环境