Leetcode 44. Wildcard Matching (Hard) (cpp)
来源:互联网 发布:淘宝代工品牌怎么样 编辑:程序博客网 时间:2024/05/16 18:39
Leetcode 44. Wildcard Matching (Hard) (cpp)
Tag: Dynamic Programming, Backtracking, Greedy, String
Difficulty: Hard
/*44. Wildcard Matching (Hard)Implement wildcard pattern matching with support for '?' and '*'.'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequence).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", "*") → trueisMatch("aa", "a*") → trueisMatch("ab", "?*") → trueisMatch("aab", "c*a*b") → false*/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 j = 1; j <= n; j++) {t[0][j] = p[j - 1] == '*' && t[0][j - 1];}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 - 1] || t[i - 1][j];}}}return t[m][n];}};
0 0
- Leetcode 44. Wildcard Matching (Hard) (cpp)
- 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
- 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
- leetcode 44. Wildcard Matching
- LeetCode 44. Wildcard Matching
- 44. Wildcard Matching -- LeetCode
- CSS3 转换(Transform)
- Homebrew
- LSTM源码分析
- maven6—pom.xml解析
- 数据采集及传输名词解释——比特率、波特率、码率、帧率
- Leetcode 44. Wildcard Matching (Hard) (cpp)
- 【二维数组】旋转方阵
- 开发一款开源爬虫框架系列(五):爬虫架构的一些新思路
- JVM学习笔记之class文件
- 团队在Github上协同开发项目流程
- 分布式缓存--系列1 -- Hash环/一致性Hash原理
- 使用mysqldump备份MySQL数据库
- 操作图像3-用pillow操作图像
- DHCP服务器配置-Centos