[Leetcode 44, Hard] Wildcard match
来源:互联网 发布:广州男装网络批发 编辑:程序博客网 时间:2024/04/30 03:08
Problem:
mplement 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
Analysis:
The solution comes from http://yucoding.blogspot.com/2013/02/leetcode-question-123-wildcard-matching.html
Solutions:
C++:
bool isMatch(string S, string P) { const char *s = S.c_str(); const char *p = P.c_str(); 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; } return false; } while (*p == '*') p++; return !*p; }Java:
Python:
0 0
- [Leetcode 44, Hard] Wildcard match
- leetcode-wildcard match
- 44、 Wildcard Matching (Hard)
- 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
- UE4学习笔记4th
- 2014款新宝来车引擎盖开关在哪里
- [Leetcode 124, Hard] Binary Tree Maximum Path Sum
- 爷爷去世了。
- 天才的大三暑假修行之旅.表面着色器(二)
- [Leetcode 44, Hard] Wildcard match
- html,js ,jsp工作学习
- Web服务器Nginx+PHP&DB服务器mysql主从(新手)-1.DB服务器配置
- 暑假习题 四
- java学习
- Twelves Monkeys (multiset解法 141 - ZOJ Monthly, July 2015 - H)
- 珍惜
- [Leetcode 68, Hard] Text Justification
- 29个你必须知道的Linux命令