leetcode Wildcard Matching
来源:互联网 发布:大学生网络安全教育ppt 编辑:程序博客网 时间:2024/06/11 08:59
Wildcard Matching
Total Accepted: 14208 Total Submissions: 100593My SubmissionsImplement 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) { const char* star=NULL; //最后一个‘*’的位置 const char* ss=s; while (*s){ if ((*p=='?')||(*p==*s)){s++;p++;continue;} if (*p=='*'){star=p++; ss=s;continue;} if (star){p = star+1;s=++ss;continue;} //这里其实就是递归的思想,不过返回比较快,算了一下,极限情况下比较次数为: //l2 * (l1-l2),一个*,后面一片a,长度最长的为3W多,乘一下也就4.5e8,不过貌似没这种样例 return false; } while (*p=='*'){p++;} return !*p; }};
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
- 手工添加jar到本地maven库
- 程序员的第一门语言 英语
- linaro-ubuntu 系统启动配置和Zedboard的VNC配置
- Ubuntu 安装 jdk
- Android Touch事件分发过程
- leetcode Wildcard Matching
- C++学习1——入门学习
- nyist 单调递增最长子序列
- win7(64位)php5.5-Apache2.4-mysql5.6环境安装
- 160个破解练习之1-Acid burn.exe
- Android中Thread、Handler、Looper、MessageQueue的原理分析
- 奥米服务 感动常在
- Time of flight cameras(TOF carmeras)
- Light OJ 1317 Throwing Balls into the Baskets 概率DP