leetcode 044 —— Wildcard Matching
2015-07-23 14:54
309 查看
Implement wildcard pattern matching with support for
思路:class Solution {
public:
bool isMatch(string s, string p) {
int i = 0, j = 0;
int star=-1;
int ss=0;
while (s[i]){
if ((s[i] == p[j]) || (p[j] == '?')){
i++;
j++;
continue;
}
if (p[j] == '*'){
star = j++;
ss = i;
continue;
}
if (star>=0){
j = star + 1;
i = ++ss;
continue;
}
return false;
}
while (p[j] == '*') j++;
if (p[j])
return false; //如果p[j]是null,那么!p[j]就是yes,如果是
else
return true;
}
};
'?'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") → false isMatch("aa","aa") → true isMatch("aaa","aa") → false isMatch("aa", "*") → true isMatch("aa", "a*") → true isMatch("ab", "?*") → true isMatch("aab", "c*a*b") → false
思路:class Solution {
public:
bool isMatch(string s, string p) {
int i = 0, j = 0;
int star=-1;
int ss=0;
while (s[i]){
if ((s[i] == p[j]) || (p[j] == '?')){
i++;
j++;
continue;
}
if (p[j] == '*'){
star = j++;
ss = i;
continue;
}
if (star>=0){
j = star + 1;
i = ++ss;
continue;
}
return false;
}
while (p[j] == '*') j++;
if (p[j])
return false; //如果p[j]是null,那么!p[j]就是yes,如果是
else
return true;
}
};
相关文章推荐
- win10系统怎么在RE中回滚到win7?
- FPGA实验——串口发送/接收学习笔记
- [ASP.NET MVC 小牛之路]14 - Unobtrusive Ajax
- Android版本和API Level对应关系
- Hadoop命令
- 算法导论-最大子数组问题-线性时间复杂度算法分析与实现
- Linux 远程控制 SSH 配置
- Linux自启动设置详解
- Search a 2D Matrix II
- C++中内置变量的初始化
- android webview js交互 第一节 (java和js交互)
- P2P平台的"我要借款"功能,是否需要上传借款人的相关资料
- [ASP.NET MVC 小牛之路]13 - Helper Method
- 高精度加法模板
- Keil 界面配置保存和共享
- Android代码内存优化建议-OnTrimMemory优化
- 查看ssh是否已启动
- P2P平台的"我要借款"功能,是否需要上传借款人的相关资料
- Swift学习: The Swift Programming Language 01
- Jfinal学习笔记