LeetCode OJ-- Wildcard Matching **@
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 **@的更多相关文章
- [OJ] Wildcard Matching (Hard)
LintCode 192. Wildcard Matching (Hard) LeetCode 44. Wildcard Matching (Hard) 第二次刷还是被这题虐. 其实就是跪在一个地方, ...
- 【leetcode】Wildcard Matching
Wildcard Matching Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any ...
- LeetCode - 44. Wildcard Matching
44. Wildcard Matching Problem's Link --------------------------------------------------------------- ...
- LeetCode 044 Wildcard Matching
题目要求:Wildcard Matching Implement wildcard pattern matching with support for '?' and '*'. '?' Matches ...
- [LeetCode] 44. Wildcard Matching 外卡匹配
Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '? ...
- Java for LeetCode 044 Wildcard Matching
Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any single character. ...
- 【leetcode】Wildcard Matching(hard) ★ 大神太牛了
Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any single character. ...
- [leetcode]44. Wildcard Matching万能符匹配
Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '? ...
- LeetCode题解-----Wildcard Matching
题目描述: '?' Matches any single character. '*' Matches any sequence of characters (including the empty ...
- LeetCode 44 Wildcard Matching(字符串匹配问题)
题目链接:https://leetcode.com/problems/wildcard-matching/?tab=Description '?' Matches any single chara ...
随机推荐
- SVN服务器详细权限控制
版权声明:本文为博主原创文章,未经博主允许不得转载. 下面是我配置SVN服务器的过程,现在把我所配置的方法,记录下来,以供其他有需要的朋友参考,需要改进的地方,请指教! 一 环境 操作系统:windo ...
- 【cl】Json学习
http://www.cnblogs.com/java-pan/archive/2012/04/07/2436507.html
- php读取zip文件(删除文件,提取文件,增加文件)实例
<?php /* php 从zip压缩文件中提取文件 */ $zip = new ZipArchive; if ($zip->open('jQuery五屏上下滚动焦点图代码.zip') = ...
- 异常Throwable类
所有异常类型都是Throwable类的子类,它派生出两个子类 Error和Exception Error类:表示紧靠程序本身无法恢复的严重错误,如内存溢出,动态链接失败,虚拟机错误 ...
- 12. Linux在线升级yum
软件包仓库源 将yum源放在/etc/yum.repo.d root@cfm880 Packages]# cd /etc/yum.repos.d/[root@cfm880 yum.repos.d]# ...
- linux下重启tomcat,日志查看
版权声明:本文为楼主原创文章,未经楼主允许不得转载,如要转载请注明来源. 一:关闭tomcat 1.使用cd命令以及常用的tab补全命令进入到tomcat bin所在的目录(可以不用到此目录也行,楼主 ...
- jquery selector checkbox
$("#competencyList input:checkbox").on("click", function () { var checkedCompete ...
- android前端开发 布局学习
元素背景设置 -------------------------------- Android中shape中的属性大全 http://www.oschina.net/question/166763_3 ...
- sql基础知识(新手必备)
一.简单查询 1.查询所有数据,查询部分列数据,列别名 SELECT * FROM 表名 SELECT 列1 AS 'BIAOTI1','BIAOTI2'=列2 FROM 表名 2.查询不重复的数据 ...
- 用定时器令P0(或其它IO口)产生多路方波
void Timer0_isr(void) interrupt 1 using 1{ static unsigned char i; //重新赋值 12M晶振计算,指令周期1uS,500x2=1mS ...