121_leetcode_Wildcard Matching
来源:互联网 发布:如何提升淘宝宝贝权重 编辑:程序博客网 时间:2024/06/05 15:32
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
1:注意特殊情况;2:遇到‘?',分别++;3:遇到‘*’的情况
bool isMatch(const char *s, const char *p) { if(s == NULL || p == NULL) { return false; } bool flag = false; const char* indexP = nullptr; const char* indexS = nullptr; while( *s != '\0') { if(*p == '?') { p++; s++; } else if(*p == '*') { while(*p == '*') { p++; } p--; indexP = p; indexS = s; flag = true; p++; } else { if(*p == *s) { p++; s++; } else { if(flag == true) { p = indexP + 1; s = ++indexS; } else { return false; } } } } while(*p == '*') { p++; } if(*s == '\0' && *p == '\0') { return true; } else { return false; } }
0 0
- 121_leetcode_Wildcard Matching
- Matching
- KMP Matching: String Matching
- KMP matching
- Bipartite Matching
- String Matching
- DP Matching
- Template matching
- Wildcard Matching
- LeetCode_Wildcard Matching
- Wildcard Matching
- Wildcard Matching
- String Matching
- String Matching
- Histogram Matching
- Wildcard Matching
- Wildcard Matching
- Wildcard Matching
- C语言的本质(2)——二进制、八进制、十六进制与十进制
- 黑马程序员——OC——ARC内存管理
- 规范定义的错误码
- 编程算法 - 连续子数组的最大和 代码(C)
- HTML文档类型
- 121_leetcode_Wildcard Matching
- [hdu 1071]The area 高斯消元
- js面对对象编程(二):属性和闭包
- ORACLE锁机制
- 依赖注入的方式
- 机器学习中的相似性度量
- 游戏中常用算法
- C语言的本质(3)——整数的本质与运算
- 用Java统计字符串中的字母、数字、空格和其他字符