LeetCode Wildcard Matching
来源:互联网 发布:c语言If else例题 编辑:程序博客网 时间:2024/06/14 09:41
题目:
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(const char *s, const char *p) {if (!*s && !*p)return true;else if (*p == *s || (*p == '?' && *s))return isMatch(s + 1, p + 1);else if (*p == '*') {bool res = false;//连续多个*与单个*效果相同while (*p == '*') p++;//若*后面没有字符,则匹配if (!*p) return true;while (*s) {const char *ts = s, *tp = p;while (*ts && (*ts == *tp || *tp == '?')) {ts++, tp++;if (*tp == '*')break;}if (!*ts && !*tp)return true;if (*tp == '*')return isMatch(ts, tp);if (!*ts) return false;s++;}return false;}elsereturn false;}};
0 0
- LeetCode: Wildcard Matching
- LeetCode : Wildcard Matching
- [LeetCode] Wildcard Matching - Iteratively
- leetcode 83: Wildcard Matching
- [Leetcode] Wildcard Matching
- [LeetCode]Wildcard Matching
- LeetCode-Wildcard Matching
- LeetCode -- Wildcard Matching
- LeetCode | Wildcard Matching
- Leetcode: Wildcard Matching
- Leetcode:Wildcard Matching
- LeetCode题解:Wildcard Matching
- LeetCode Wildcard Matching
- [Leetcode] Wildcard Matching (Java)
- LeetCode OJ:Wildcard Matching
- Leetcode: Wildcard Matching
- Wildcard Matching -- LeetCode
- [LeetCode] Wildcard Matching
- Java集合类详解
- 格式化字符串
- MVC return View("")问题
- Linux内核开发之阻塞/非阻塞IO----等待对列
- 你先把头发绑起来”,“你先把眼镜摘下来”,“你先把wifi关了”
- LeetCode Wildcard Matching
- python 图 遍历-深度优先和广度优先 II
- Linux 多线程应用中如何编写安全的信号处理函数
- NSNumber Compare的崩溃
- 我的android开发之路
- 我的shiro之旅: 十七 跨域session共享的一种解决方法
- 不用循环,计算一串数字里面有多少个1
- weblogic的BEA-000438错误解决
- java,C#插入数据到oracle11g数据库并返回其id