Wildcard Matching
来源:互联网 发布:python语言就业前景 编辑:程序博客网 时间:2024/05/16 08:16
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) { bool star=false; const char *prevS=NULL,*prevP=NULL; while(*s!='\0'){ if(*p=='*'){ star=true; prevP=++p; prevS=s; } else{ if(*p=='?'||*p==*s) { s++; p++; } else{ if(!star) return false; p=prevP; s=prevS++; } } } while(*p=='*') p++; return *p=='\0'; }};
0 0
- Wildcard Matching
- Wildcard Matching
- Wildcard Matching
- Wildcard Matching
- Wildcard Matching
- Wildcard Matching
- Wildcard Matching
- Wildcard Matching
- Wildcard Matching
- Wildcard Matching
- Wildcard Matching
- Wildcard Matching
- Wildcard matching
- Wildcard Matching
- Wildcard Matching
- Wildcard Matching
- Wildcard Matching
- Wildcard Matching
- UVA 10714
- 手把手教你用matlab生成STM32官方IIR滤波器的系数(三)
- UVA10128 - Queue(dp)
- BZOJ 1251 序列终结者 Splay
- Zxing和QR CODE 生成与解析二维码实例(带logo篇)
- Wildcard Matching
- jsp-简单标签及案例
- 循环-10. 求序列前N项和
- win8.1 up1 64位下安装 64位的Ubuntu14.10
- [Leetcode]Partition List
- ext2文件系统
- pl*sql基础(三)之函数
- 寄存器操作
- HDU—— 1029 Ignatius and the Princess IV