Wildcard Matching
来源:互联网 发布:数据开放平台浏览器 编辑:程序博客网 时间:2024/05/21 17:48
http://discuss.leetcode.com/questions/222/wildcard-matching
解法一
class Solution {public: bool isMatch(const char *s, const char *p) { // Start typing your C/C++ solution below // DO NOT write int main() function if (*p == '*'){//return true; while(*p == '*') ++p; if (*p == '\0') return true; while(*s != '\0' && !isMatch(s,p)){ ++s; } return *s != '\0'; } else if (*p == '\0' || *s == '\0') return *p == *s; else if (*p == *s || *p == '?') return isMatch(++s,++p); else return false; }};
解法二
class Solution {public:bool isMatch(const char *s, const char *p) { // Start typing your C/C++ solution below // DO NOT write int main() function if(!s && !p) return true; const char *star_p=NULL,*star_s=NULL; while(*s) { if(*p == '?' || *p == *s) { ++p,++s; }else if(*p == '*') { //skip all continuous '*' while(*p == '*') ++p; if(!*p) return true; //if end with '*', its match. star_p = p; //store '*' pos for string and pattern star_s = s; }else if((!*p || *p != *s) && star_p) { s = ++star_s; //skip non-match char of string, regard it matched in '*' p = star_p; //pattern backtrace to later char of '*' }else return false; } //check if later part of p are all '*' while(*p) if(*p++ != '*') return false; return true;}};
- 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
- jsp页面间传递的参数乱码的解决办法
- 插入排序
- 启动tomcat的 startup.bat屏幕一闪而过
- 项目管理的酸甜苦辣
- 对软件测试团队“核心价值”的思考
- Wildcard Matching
- Maven(工作Session)
- 一位ACMer过来人的心得
- java 简易闹钟
- Android菜单目录的横向排列方法
- GUID 和 接口
- AAM(Active Appreance Model)算法用于人脸识别总结
- 二分查找的感悟
- mpstat命令