• leetcode[44]Wildcard Matching


    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") → 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(const char *s, const char *p) {
         const char *ss=NULL;
         const char *pp=NULL;
         while(*s!='')
         {
             if(*p==*s||*p=='?')
             {
                 s++;
                 p++;
                 continue;
             }
             if(*p=='*')
             {
                 pp=p;
                 ss=s;
                  p++;
                  continue;
             }
             if(pp!='')
             {
                 s=ss+1;
                 p=pp+1;
                 ss++;
                 continue;
             }
             return false;
         }
         while(*p=='*')p++;
         return *p=='';
        }
    };
  • 相关阅读:
    pip包安装问题
    spyder中让生成的图像单独在窗口中显示
    错误的英语提示翻译 以及经常犯的无错误
    程序结构
    运算符
    js jq计算器
    jQuery筛选选择器
    jQuery获取标签信息
    javascript的getTime函数
    animate动画
  • 原文地址:https://www.cnblogs.com/Vae1990Silence/p/4283570.html
Copyright © 2020-2023  润新知