Wildcard Matching
来源:互联网 发布:网络尿性的意思 编辑:程序博客网 时间:2024/05/29 12:14
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) {const char *sl = 0, *pl = 0;while(*s != '\0'){if (*s == *p || '?' == *p){s++;p++;}else if ('*' == *p){sl = s;pl = p;p++;}else if (pl != 0){s = ++sl;p = pl + 1;}elsereturn false;}while('*' == *p)p++;return '\0' == *p;}};
回溯加减枝
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
- 好程序员训练营,让你成为名副其实的好程序员
- 燃烧的三国开发笔记 1
- Spring aop 拦截器(即面向切面编程)
- Python线程通信
- sql 查询行号
- Wildcard Matching
- 解决impala运行时出现的UnicodeEncodeError: 'ascii' codec can't encode characters in position问题
- Eclipse 快捷键
- java--正则表达式学习
- Visual studio 2010出现“error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏”解决方案
- hotspot源码(JDK7)-源码结构说明
- C++笔试面试(算法题集二)
- 关于缓存的深度剖析
- 如何清除归档日志