Leetcode 10. Regular Expression Matching (Hard) (cpp)
来源:互联网 发布:林弯弯的淘宝店外套 编辑:程序博客网 时间:2024/05/22 06:49
Leetcode 10. Regular Expression Matching (Hard) (cpp)
Tag: Dynamic Programming, Backtracking, String
Difficulty: Hard
/*10. Regular Expression Matching (Hard)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") → falseisMatch("aa","aa") → trueisMatch("aaa","aa") → falseisMatch("aa", "a*") → trueisMatch("aa", ".*") → trueisMatch("ab", ".*") → trueisMatch("aab", "c*a*b") → true*/class Solution {public:bool isMatch(string s, string p) {int m = s.size(), n = p.size();vector<vector<bool>> t(m + 1, vector<bool>(n + 1, false));t[0][0] = true;for (int i = 1; i <= m; i++) {t[i][0] = false;}for (int j = 1; j <= n; j++) {t[0][j] = j > 1 && '*' == p[j - 1] && t[0][j - 2];}for (int i = 1; i <= m; i++) {for (int j = 1; j <= n; j++) {if (p[j - 1] != '*') {t[i][j] = t[i - 1][j - 1] && (s[i - 1] == p[j - 1] || '.' == p[j - 1]);}else {t[i][j] = t[i][j - 2] || (s[i - 1] == p[j - 2] || '.' == p[j - 2]) && t[i - 1][j];}}}return t[m][n];}};
0 0
- Leetcode 10. Regular Expression Matching (Hard) (cpp)
- LeetCode 10. Regular Expression Matching(hard)
- (Leetcode)10.Regular Expression Matching(hard)
- 10. Regular Expression Matching-hard
- 【LeetCode】10.Regular Expression Matching(hard)解题报告
- [Leetcode 10, Hard] Regular Expression Matching
- Regular Expression Matching (Leetcode hard algorithm problem)
- [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
- leetcode 10. Regular Expression Matching
- Leetcode 10. Regular Expression Matching
- 用代码证明自己闲的蛋疼(三)——回溯法做数独
- C#中数组、ArrayList和List三者的区别
- 第十二周项目2 - 操作用邻接表存储的图
- maven+spring+springmvc+mybatis+ajax 框架下实现简单的聊天室
- 一套面试题
- Leetcode 10. Regular Expression Matching (Hard) (cpp)
- ConEmu设置当前目录打开右键菜单
- 第13周项目1-Prim的算法验证
- 搭建spring框架的时候,web.xml中的spring相关配置,可以不用配置ContextLoaderListener(即只配DispatcherServlet)吗?
- 第十三周项目1-dijkstra算法
- Java Web项目在Mac系统上启动时提示nodename nor servname provided的解决办法
- ubuntu 防火墙使用
- #Codeforces 381 [div2] D. Alyona and a tree 【树链剖分 + 优先队列】
- Android UI-聊天界面