博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Leetcode_Wildcard Matching
阅读量:7092 次
发布时间:2019-06-28

本文共 1409 字,大约阅读时间需要 4 分钟。

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") → falseisMatch("aa","aa") → trueisMatch("aaa","aa") → falseisMatch("aa", "*") → trueisMatch("aa", "a*") → trueisMatch("ab", "?*") → true

isMatch("aab", "c*a*b") → false

class Solution {public:    bool isMatch(const char *s, const char *p) {       const char * ptr;       const char *str;       bool start = false;       for(ptr=p,str=s; *str!='\0'  ; ){           switch(*ptr){               case '?':               str++,ptr++;               break;               case '*':               start = true;               while(*ptr == '*')                 ptr++;               if(*ptr=='\0')               return true;               p = ptr;               s = str;               break;               default:               if(*ptr != *str){                   if(!start)                   return false;                   ptr = p;                   str = s+1;                   s=s+1;               }              else{                  ptr++;                  str++;              }           }       }       while(*ptr=='*')  ptr++;              return (*ptr == '\0');    }};

转载地址:http://pmnql.baihongyu.com/

你可能感兴趣的文章
[译]go错误处理
查看>>
前端性能优化常用总结
查看>>
jqGrid的rowNum属性默认值、-1情况的介绍
查看>>
css选择器
查看>>
通知!TargetSdkVersion新规执行在即!
查看>>
什么是web3.js以及应用
查看>>
dokuwiki安装问题
查看>>
[vuex] getters should be function but "getters.default" is {}.
查看>>
体验URLOS自动快照备份 5分钟一次的快照备份真的很爽
查看>>
以「蜘蛛数据」之名,赋予每个人DAPP评测的能力
查看>>
Spring详解3.Bean的装配
查看>>
搭建webpack简易脚手架
查看>>
前端技术周刊 2019-01-28:VSCode
查看>>
【算法初探】数组、链表与选择排序
查看>>
自定义微信分享样式
查看>>
网络存储之 NFS
查看>>
2.两数相加
查看>>
纯用NumPy实现神经网络
查看>>
设计模式(python实现):策略模式
查看>>
1分钟熟悉webpack
查看>>