LeetCode-Wildcard Matching
来源:互联网 发布:h5手机页面源码下载 编辑:程序博客网 时间:2024/06/13 09:23
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
Solution:Code:
<span style="font-size:14px;">class Solution {public: bool isMatch(const char *s, const char *p) { int indexS = 0, indexP = 0, preS = -1, preP = -1; while (s[indexS] != '\0') { if (s[indexS] == p[indexP] || p[indexP] == '?') { ++indexS; ++indexP; continue; } if (p[indexP] == '*') { preS = indexS; preP = indexP; ++indexP; continue; } if (preP != -1) { ++preS; indexS = preS; indexP = preP+1; continue; } return false; } while (p[indexP] != '\0' && p[indexP] == '*') ++indexP; return p[indexP] == '\0'; }};</span>
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
- TODO
- NSData与UIImage之间的转换
- php设计模式:工厂模式
- 黑马程序员-单例设计模式
- Linux 下远程桌面 Remmina 无法连接
- LeetCode-Wildcard Matching
- hadoop能用到的系统端口
- MFC中CString char* int的相互转换
- 在Linux下分析 C程序的性能
- php设计模式笔记:单例模式
- 关于CEGUI的几点不解
- linux shell 动态生成 数组系列 seq使用技巧
- 关于.Net中,在数据绑定日期格式的问题
- HDU4952:Number Transformation