LeetCode - 44. Wildcard Matching
44. Wildcard Matching
Problem's Link
----------------------------------------------------------------------------
Mean:
给你一个字符串和一个自动机,问你自动机可否接收这个字符串.
analyse:
由于自动机的模式很简单,所以可以直接模拟.
Time complexity: O(N)
view code
* -----------------------------------------------------------------
* Copyright (c) 2016 crazyacking.All rights reserved.
* -----------------------------------------------------------------
* Author: crazyacking
* Date : 2016-03-06-19.05
*/
#include <queue>
#include <cstdio>
#include <set>
#include <string>
#include <stack>
#include <cmath>
#include <climits>
#include <map>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long(LL);
typedef unsigned long long(ULL);
const double eps(1e-8);
class Solution
{
public:
bool isMatch(string s, string p)
{
int star_=-1,ts;
int ss(0),pp(0);
while(ss<s.length())
{
if(s[ss]==p[pp] || p[pp]=='?')
{
++ss,++pp;
continue;
}
if(p[pp]=='*')
{
star_=pp++,ts=ss;
continue;
}
if(star_!=-1)
{
pp=star_+1,ss=++ts;
continue;
}
return false;
}
while(p[pp]=='*')
++pp;
return (pp==p.length());
}
};
int main()
{
string s1,s2;
while(cin>>s1>>s2)
{
Solution solution;
bool res=solution.isMatch(s1,s2);
if(res)
cout<<"True"<<endl;
else
cout<<"False"<<endl;
}
return 0;
}
/*
*/
转载于:https://www.cnblogs.com/crazyacking/p/5254064.html
LeetCode - 44. Wildcard Matching相关推荐
- 【To Understand! 重点 递归 动态规划 正则表达式匹配】LeetCode 44. Wildcard Matching
LeetCode 44. Wildcard Matching Solution1:我的答案 递归,时间复杂度是O(2n)O(2n)O(2^n)因为超时未能AC 只是记录一下,以警示后人-- class ...
- LeetCode: 44. Wildcard Matching
LeetCode: 44. Wildcard Matching 题目描述 Implement wildcard pattern matching with support for '?' and '* ...
- [leetcode 44] Wildcard Matching
Implement wildcard pattern matching with support for '?' and '*'. '? ' Matches any single character. ...
- [LeetCode] #44 Wildcard Matching
mplement wildcard pattern matching with support for '?' and '*'. '?' Matches any single character. ' ...
- LeetCode 10. Regular Expression Matching / 44. Wildcard Matching
10. Regular Expression Matching 经典DP题目,比较复杂,需要多复习. dp[i][j] 表示 s 下标0~i,p 下标0~j 是否能够匹配 dp[i-1][j-1] ...
- 【LeetCode】44. Wildcard Matching (2 solutions)
Wildcard Matching Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any ...
- 44. Wildcard Matching 通配符匹配
Title 给定一个字符串 (s) 和一个字符模式 § ,实现一个支持 '?' 和 '*' 的通配符匹配. '?' 可以匹配任何单个字符. '*' 可以匹配任意字符串(包括空字符串). 两个字符串完全 ...
- [OJ] Wildcard Matching (Hard)
LintCode 192. Wildcard Matching (Hard) LeetCode 44. Wildcard Matching (Hard) 第二次刷还是被这题虐. 其实就是跪在一个地方, ...
- [LeetCode] Wildcard Matching 题解
6. Wildcard Matching 题目 Implement wildcard pattern matching with support for '?' and '*'. '?' Matche ...
最新文章
- Bound Found POJ - 2566(尺取法)
- apache 2.4 httpd.conf 详解_Linux Centos服务子系统详解
- jzoj4279-[NOIP2015模拟10.29B组]树上路径【树形dp】
- wechat code miniprogram 没有找到可以构建的 NPM 包
- python入门之函数调用-python之函数入门
- Handler原理分析
- python 2 版本中的input() 和 raw_input() 函数的比较
- 路由添加失败 参数错误_Django框架基础之路由详解 | 技术
- HTTP-meta标签
- GB28181协议--GB28181协议简介
- Power Apps 拍照上传
- 深入浅出聊机器学习西瓜书
- mysql中rand的用法_MySQL RAND()用法及代码示例
- Elasticsearch:sniffing 的最佳实践:What, when, why, how
- 黎明纪元-3D魔幻世界角色扮演游戏
- 【JZOJ5353】【NOIP2017提高A组模拟9.9】村通网【最小生成树】
- 关于Mybatis 异常BindingException: Type interface XXXX is not known to the MapperRegistry.
- 快速排序算法Quicksort()
- Kaggle小技巧:TTA(test time augmentation)测试时增强
- git 批量删除 tag 标签
热门文章
- iOS UIWebView清除缓存
- storage theory
- 虚函数virtual
- 最大的脚本网站_网站页面性能优化注意事项
- VS2010 Cocos2d-x 2.2创建模板
- 使用Memory Analyzer tool(MAT)分析内存泄漏(二)
- SQL2005中row_number( )、rank( )、dense_rank( )、ntile( )函数的用法(1)
- Ubuntu 10.04 is coming
- MS Sql Server 数据库或表修复(DBCC CHECKDB)
- 物尽其用-让推荐系统成为你学习的助手