https://oj.leetcode.com/problems/wildcard-matching/

模拟通配符的匹配

做法非常好

 class Solution {
public:
bool isMatch(const char *s, const char *p) {
bool hasStar = false;
const char *str,*ptr;
for(str = s,ptr = p; *str != '\0'; str++,ptr++)
{
switch(*ptr)
{
// 相当于做了一次匹配,都往前走1
case '?':
break;
case '*':
hasStar = true;
s = str; // 记录,前面的已经处理好了
p = ptr;
while(*p == '*') p++; // 相当于把*先映射成空
if(*p == '\0')
return true;
str = s - ;
ptr = p - ;
break;
default:
if(*str != *ptr)
{
if(!hasStar)
return false;
s++; // s往前挪一个,相当于 * 多映射一个 回到出现*的位置开始 再往前加一个 再进行下面的匹配
str = s -;
ptr = p -;
}
}
}
while(*ptr == '*')
ptr++;
return (*ptr == '\0');
}
};

LeetCode OJ-- Wildcard Matching **@的更多相关文章

  1. [OJ] Wildcard Matching (Hard)

    LintCode 192. Wildcard Matching (Hard) LeetCode 44. Wildcard Matching (Hard) 第二次刷还是被这题虐. 其实就是跪在一个地方, ...

  2. 【leetcode】Wildcard Matching

    Wildcard Matching Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any ...

  3. LeetCode - 44. Wildcard Matching

    44. Wildcard Matching Problem's Link --------------------------------------------------------------- ...

  4. LeetCode 044 Wildcard Matching

    题目要求:Wildcard Matching Implement wildcard pattern matching with support for '?' and '*'. '?' Matches ...

  5. [LeetCode] 44. Wildcard Matching 外卡匹配

    Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '? ...

  6. Java for LeetCode 044 Wildcard Matching

    Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any single character. ...

  7. 【leetcode】Wildcard Matching(hard) ★ 大神太牛了

    Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any single character. ...

  8. [leetcode]44. Wildcard Matching万能符匹配

    Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '? ...

  9. LeetCode题解-----Wildcard Matching

    题目描述: '?' Matches any single character. '*' Matches any sequence of characters (including the empty ...

  10. LeetCode 44 Wildcard Matching(字符串匹配问题)

    题目链接:https://leetcode.com/problems/wildcard-matching/?tab=Description   '?' Matches any single chara ...

随机推荐

  1. Android 通过按钮弹出系统菜单(通过Button显示菜单)转

    myButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { openOpti ...

  2. AndroidManifest.xml

    一.关于AndroidManifest.xml AndroidManifest.xml 是每个android程序中必须的文件.它位于整个项目的根目录,描述了package中暴露的组件(activiti ...

  3. [vB.NET]为控件添加鼠标悬浮时的提示气泡

    实例代码: Dim k As ToolTip k = New ToolTip() k.AutoPopDelay = '显示出气泡后的延时时间(毫秒) k.InitialDelay = '出现前的延时( ...

  4. Python自动化 【第二篇】:Python基础-列表、元组、字典

    本节内容 模块初识 .pyc简介 数据类型初识 数据运算 列表.元组操作 字符串操作 字典操作 集合操作 字符编码与转码 一.模块初识 Python的强大之处在于他有非常丰富和强大的标准库和第三方库, ...

  5. RegExp 对象的三个方法:compile()、exec()、test()

    这三个都是RegExp对象下的三个方法,使用方法是一致得. 使用方法:RegExpObject.方法() 方法解析:其实就是根据定义好的正则对象,调用对应的方法. 1.RegExpObject.com ...

  6. 数据库中int类型存在空数据开发过程中model和dal层处理方法

    model层 public Int32? IsFullAttendance { get; set; } dal层  if (dr["IsFullAttendance"] + &qu ...

  7. poj 2987 最大权闭合图

    Language: Default Firing Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 8744   Accept ...

  8. Xcode 字体 设置-- Xcode family没有显示的字体

    前往文件夹 -> /Users/user/Library/Developer/Xcode/UserData/FontAndColorThemes/  (user改为自己的用户名) -----如果 ...

  9. C语言-------多文件编译

    (1)前段时间,学长讲解宏的一些知识  也提起了那个多文件编译,同过看别人的博客,自己也懂了一些,现在来总结一下这个多文件编译,其实和java里面的那个class的调用好像有联系 其定义即可以理解成: ...

  10. SVM2---核函数的引入

    前边总结了线性SVM,最终转化为一个QP问题来求解.后来又考虑到非线性SVM,如果特征特别特别多的话,直接使用QP的话求解不了,我们经过一系列的转化,把这一问题转化为训练集大小n量级的QP问题. ht ...