leetcod Wildcard Matching
来源:互联网 发布:泰丰售电软件 编辑:程序博客网 时间:2024/06/07 05:45
上来想到用递归求解,结果超时,先是考虑把多个连续的*合成一个*处理,仍然超时,最后在http://blogs.com/x1957/p/3517096.html处看到,可以通过类似回溯的方式求解
class Solution {public: bool isMatch(const char *s, const char *p) { const char* star = nullptr; const char* rs = nullptr; while(*s) { if(*s == *p || *p == '?') { //match s++; p++; continue; } if(*p == '*') { star = p; // record star p++; //match from next p rs = s; // record the position of s , star match 0 continue; } if(star != nullptr) { //if have star in front then backtrace p = star + 1; //reset the position of p s = rs + 1; rs ++; //star match 1,2,3,4,5.... continue; } return false; //if not match return false } while(*p == '*') p++; //skip continue star return *p == '\0'; // successful match }};
0 0
- leetcod 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
- jquery中prop()方法和attr()方法的区别浅析
- AjaxControlToolkit Multiple Files Upload
- c++实现汉诺塔
- 一个好用的短连接服务,mark备用
- sleep()和 wait()有什么区别
- leetcod Wildcard Matching
- getNextElement与nextSibling的疑惑
- 深入浅出Java设计模式之适配器模式
- 在Windows Server 2008中文件夹中的图片不能显示缩略图
- .net序列化及反序列化
- Java SSL例子
- 联想发力路由 剑指netgear
- 比特币矿机制造商HashFast因退款几乎一贫如洗
- HibernateOptimisticLockingFailureException