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 ...
随机推荐
- [CF442B] Andrey and Problem (概率dp)
题目链接:http://codeforces.com/problemset/problem/442/B 题目大意:有n个人,第i个人出一道题的概率是pi,现在选出一个子集,使得这些人恰好出一个题的概率 ...
- android开发之单选按钮
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android=&q ...
- 2016-08-05:samba服务器配置
centos samba服务器配置 配置smb.conf文件 [share] path = /home/lee writable = yes 添加smb用户 smbpasswd -a root 启动s ...
- PIC32MZ tutorial -- Watchdog Timer
Watchdog is a very necessary module for embedded system. Someone said that embedded system operates ...
- JS 計算文本域還能輸入多少個字符
//輸入計數 //count:能輸入的數據總量 function Calculation(v, count) { var span = $(v).next(); va ...
- 用tcc遇到的一个大坑
在centos6.5 x86_64服务器上编译安装完tcc, 版本0.9.25(在github上clone的),似乎一切正常 但当用tcc来编译"hello, world"程序时, ...
- 为什么V8引擎这么快?
目录(?)[-] 高速引擎的需求 语言本身的问题 JIT编译 JIT Compile 垃圾回收管理 内嵌缓存inline cache 隐藏类 内嵌缓存Inline Cache 机器语言的特性 附录熟悉 ...
- scala 学习: 逆变和协变
scala 逆变和协变的概念网上有很多解释, 总结一句话就是 参数是逆变的或者不变的,返回值是协变的或者不变的. 但是为什么是这样的? 协变: 当s 是A的子类, 那么func(s) 是func(A) ...
- mysql convert
SELECT id,boshidianshu,boshidianshu_shuzi,CONVERT(REPLACE(boshidianshu, '个', ''),SIGNED) aaa from lg ...
- JNI Local Reference Changes in ICS
[This post is by Elliott Hughes, a Software Engineer on the Dalvik team. — Tim Bray] If you don’t wr ...