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. java中&与&&的区别

    我想很多人在学习java的时候,或者面试时都会遇到 &和&& 然而,如果你没有真正的理解他们的意思,这会给你思路上面带来很大的麻烦 在这篇blog中,当你看完了以后,你会发现, ...

  2. JDBC事务处理

    关于事务: 1.一个事务中的多个操作应该公用一个connection,如果每一个操作都用不同的connection,事务将无法回滚. 2.具体步骤: 1).在事务开始前,应该取消事务的自动提交,即设置 ...

  3. WinCE6.0多国语言软键盘

    N久以前写过一篇<WinCE下自定义的大软键盘>,这个自定义软键盘就是为RM905a+项目来做的.RM905a+的系统分辨率是640*480,WinCE原生键盘小的太小,大的又太大.所以就 ...

  4. myeclipse自动排版

    myeclipse代码排版方式有两种: 1. ctr+f 实现自动排版: 2. myeclipse->Preference->Java->Editor->Sava Action ...

  5. PCI Express(二) - Topology

    原文出处:http://www.fpga4fun.com/PCI-Express2.html Point-to-point architecture At 2.5Gbps, the PCI Expre ...

  6. DDNS -VPN设置方法

    背景分析:一般情况下企业网络都是专线,也就是静态公网IP,但是也有一些是刚起步的小公司和一些网络需求不是很高的企业. 当前,由于公司是刚起步的小公司,网络是PPPOE拨号,但是又是总部和分部分开的,另 ...

  7. JS动态获取数据

    JS访问数据,有实时获取数据的时候,请加上时间戳 如:'&stampflag=' + Math.round(new Date().getTime() / 1000); 因为有的浏览器(如IE9 ...

  8. MFC的自定义消息的定义与使用

    自定义消息的响应和资源消息的响应有很多类似之处:资源消息的响应是以资源的ID号作为标识的:自定义的消息要自己声明消息ID. 一.           定义: 第一步要声明消息: #define WM_ ...

  9. windows2008r2环境双实例安装mysql5.6

    windows2008r2环境双实例安装mysql5.6 环境:windows2008 r2 标准版 1.默认安装了一个mysql5.6端口为3306 2.使用msi文件安装需要.net4.0支持,安 ...

  10. DIRECTORY_SEPARATOR 和 PATH_SEPARATOR的区别

    DIRECTORY_SEPARATOR:目录分隔符,linux上就是’/’    windows上是’\’ PATH_SEPARATOR:路径分隔符,include多个路径使用,在win下,当你要in ...