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. Handler基本概念

    Handler基本概念: Handler主要用于异步消息的处理:当发出一个消息之后,首先进入一个消息队列,发送消息的函数即刻返回,而另外一个部分逐个的在消息队列中将消息取出,然后对消息进行出来,就是发 ...

  2. zero ice 如何获取本地以及对端IP 地址及端口号

    // 在客户端显示端点连接IP及端口号信息 static void show_endpoint(const Ice::ObjectPrx &proxy) { Ice::ConnectionPt ...

  3. [ActionScript 3.0] AS3.0 简单封装Socket的通信

    Socket服务器 package com.controls.socket { import com.models.events.AppEvent; import com.models.events. ...

  4. 关于SoCFPGA 编译问答

    1.在Qsys里面添加了一个新的组件(不是hps里面的东西),挂在Avalon总线上,如添加了一个新ADC组件,是否需要重新编译dtb. 答:  不需要. 2.修改了相关Qsys里面的东西,是否也需要 ...

  5. 新建jsp报错“The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path”

    今天新建jsp文件时,就报错“Visual Page Editor has experimental support for Windows 64-bit”,然后刚好stackoverflow上面有这 ...

  6. Visual Studio 2013 编译CEF步骤

    If you'd like to build the Chromium Embedded Framework (a wrapper for Chromium, for creating browser ...

  7. android开发--(SimpleAdapter)运用

    SimpleAdapter的参数说明  第一个参数 表示访问整个android应用程序接口,基本上所有的组件都需要  第二个参数表示生成一个Map(String ,Object)列表选项    第三个 ...

  8. NHibernate系列文章八:NHibernate对象一级缓存

    摘要 Nhibernatea缓存非常强大,按照缓存存储在Session对象还是SessionFactory对象分为一级缓存和二级缓存. 一级缓存存在于Session对象里,也叫Session缓存,由S ...

  9. 用vector容器代替数组 ——使用数组初始化vector对象

    在C++中,我们不能用数组直接初始化另一数组,而只能创建新的数组,然后显式的把原数组的元素逐个复制给新的数组. 按照C语言中的做法: const size_t arry_size=6; int int ...

  10. 30、shiro框架入门2,关于Realm

    1.Jdbc的Realm链接,并且获取权限 首先创建shiro-jdbc.ini的配置文件,主要配置链接数据库的信息 配置文件中的内容如下所示 1.变量名=全限定类名会自动创建一个类实例 2.变量名. ...