leetcode-wildcard matching-ZZ
http://yucoding.blogspot.com/2013/02/leetcode-question-123-wildcard-matching.html
几个例子:
(1)
acbdeabd
a*c*d
(2)
acbdeabdkadfa
a*c*dfa
Analysis:
For each element in s
If *s==*p or *p == ? which means this is a match, then goes to next element s++ p++.
If p=='*', this is also a match, but one or many chars may be available, so let us save this *'s position and the matched s position.
If not match, then we check if there is a * previously showed up,
if there is no *, return false;
if there is an *, we set current p to the next element of *, and set current s to the next saved s position.
e.g.
abed
?b*d**
a=?, go on, b=b, go on,
e=*, save * position star=3, save s position ss = 3, p++
e!=d, check if there was a *, yes, ss++, s=ss; p=star+1
d=d, go on, meet the end.
check the rest element in p, if all are *, true, else false;
Note that in char array, the last is NOT NULL, to check the end, use "*p" or "*p=='\0'".
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
class Solution {public: bool isMatch(const char *s, const char *p) { // Start typing your C/C++ solution below // DO NOT write int main() function const char* star=NULL; const char* ss=s; while (*s){ if ((*p=='?')||(*p==*s)){s++;p++;continue;} if (*p=='*'){star=p++; ss=s;continue;} if (star){ p = star+1; s=++ss;continue;} return false; } while (*p=='*'){p++;} return !*p; }}; |
leetcode-wildcard matching-ZZ的更多相关文章
- LeetCode: Wildcard Matching 解题报告
Wildcard MatchingImplement wildcard pattern matching with support for '?' and '*'. '?' Matches any s ...
- [LeetCode] Wildcard Matching 题解
6. Wildcard Matching 题目 Implement wildcard pattern matching with support for '?' and '*'. '?' Matche ...
- [LeetCode] Wildcard Matching 外卡匹配
Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any single character. ...
- [Leetcode] Wildcard Matching
Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any single character. ...
- [leetcode]Wildcard Matching @ Python
原题地址:https://oj.leetcode.com/problems/wildcard-matching/ 题意: Implement wildcard pattern matching wit ...
- [LeetCode] Wildcard Matching 字符串匹配,kmp,回溯,dp
Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any single character. ...
- [Leetcode] Wildcard matching 通配符匹配
Implement wildcard pattern matching with support for'?'and'*'. '?' Matches any single character. '*' ...
- leetcode Wildcard Matching greedy algrithm
The recursive program will result in TLE like this: class Solution { public: bool isMatch(const char ...
- [LeetCode]Wildcard Matching 通配符匹配(贪心)
一開始採用递归写.TLE. class Solution { public: bool flag; int n,m; void dfs(int id0,const char *s,int id1,co ...
- [Leetcode][Python]44:Wildcard Matching
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 44:Wildcard Matchinghttps://oj.leetcode ...
随机推荐
- J15W-J45W铜制截止阀厂家,J15W-J45W铜制截止阀价格 - 专题栏目 - 无极资讯网
无极资讯网 首页 最新资讯 最新图集 最新标签 搜索 J15W-J45W铜制截止阀 无极资讯网精心为您挑选了(J15W-J45W铜制截止阀)信息,其中包含了(J15W-J45W铜制截止阀)厂家,( ...
- Android Studio的串口通讯开发
基于android-serialport-api实现 前言RS232标准接口UARTRS232与UART转接下载 NDK 和构建工具创建支持 C/C++ 的新项目编译C/C++代码串口通讯原理关于校验 ...
- 那些H5用到的技术(3)——屏幕场景滑动
前言Swiper.js一些需要我们手动设置的参数排版元素需要设置position:absolute绝对元素定位swiperAnimate方法的使用动画播放完成之后的监听上滑提示屏幕适配的问题Anima ...
- (转)合格linux运维人员必会的30道shell编程面试题及讲解
超深度讲解shell高级编程实战,截至目前shell编程课程国内培训机构最细的课程,不信请看学员表现的水平. 课程牛不牛,不是看老师.课表,而是看培养的的学生水平,目前全免费中伙伴们赶紧看啊. htt ...
- 远控项目(Windows Socket)
实现内容(屏幕,鼠标,键盘实时控制) 控制端: #pragma once #ifndef keybd_H #define keybd_H #include <stdio.h> #inclu ...
- 腾讯云AI应用产品总监王磊:AI 在传统产业的最佳实践
欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 背景:5月23-24日,以"焕启"为主题的腾讯"云+未来"峰会在广州召开,广东省各级政府机构领导.海 ...
- JQuery JSON Servlet
<script type="text/javascript" src="js/jquery-1.10.2.js"></script> & ...
- pyquery库简介
html = '''<div><ul><li class="item-0">li0</li><li class="i ...
- 二:Nexus知识
Nexus访问 Http://localhost:8080/nexus Nexus登陆 用户:admin 密码:admin123 Nexus仓库 nexus的仓库类型分为以下四种: group: 仓库 ...
- bash的常用功能呢
一.tab键可以自动补齐命令 二.命令历史 1.history 查看之前敲过的所有命令 2.!历史命令编号 调用历史的某一个命令 三.命令别名 1.设置别名 alias 别名=‘命令’ 2.移除 ...