首页 > 其他 > 详细

LeetCode – Refresh – Wildcard Matching

时间:2015-03-22 16:23:10      阅读:206      评论:0      收藏:0      [点我收藏+]

This question is different from Regular Expression Matching.

Because this does not need totally match. We just have to much p is part of s.

 1 class Solution {
 2 public:
 3     bool isMatch(const char *s, const char *p) {
 4         const char *olds = s, *oldp = p;
 5         bool star = false;
 6         while (*s) {
 7             if (*s != *p) {
 8                 if (*p == ?) {
 9                     s++, p++;
10                 } else if (*p == *) {
11                     while (*p == *) p++;
12                     if (*p == \0) return true;
13                     star = true;
14                     olds = s, oldp = p;
15                 } else if (star) {
16                     olds++;
17                     s = olds, p = oldp;
18                 } else return false;
19             } else s++, p++;
20         }
21         while (*p == *) p++;
22         return *p == \0;
23     }
24 };

 

LeetCode – Refresh – Wildcard Matching

原文:http://www.cnblogs.com/shuashuashua/p/4357466.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!