【leetcode】Wildcard Matching
Wildcard Matching
Implement wildcard pattern matching with support for '?' and '*'.
'?' Matches any single character.
'*' Matches any sequence of characters (including the empty sequence). The matching should cover the entire input string (not partial). The function prototype should be:
bool isMatch(const char *s, const char *p) Some examples:
isMatch("aa","a") → false
isMatch("aa","aa") → true
isMatch("aaa","aa") → false
isMatch("aa", "*") → true
isMatch("aa", "a*") → true
isMatch("ab", "?*") → true
isMatch("aab", "c*a*b") → false
class Solution {
public:
bool isMatch(const char *s, const char *p) {
if(*s=='\0'&&*p=='\0') return true;
if(*s!='\0'&&*p=='\0') return false;
if(*s=='\0'&&*p!='\0') return false;
if(*p=='*')
{
while(*p=='*') p++;
while(*s!='\0')
{
if(isMatch(s,p)) return true;
s++;
}
return isMatch(s,p);
}
else if(*p=='?')
{
return isMatch(s+,p+);
}
else
{
return (*s==*p&&isMatch(s+,p+));
}
return false;
}
};
class Solution {
public:
bool isMatch(const char *s, const char *p) {
const char* afterStarPositionP=NULL;
const char* afterStarPositionS=NULL;
while(*s!='\0')
{
if(*s==*p||*p=='?')
{
s++;p++;
continue;
}
else if(*p=='*')
{
p++;
afterStarPositionP=p;
afterStarPositionS=s;
}
else
{
if(afterStarPositionP!=NULL)
{
afterStarPositionS++;
s=afterStarPositionS;
p=afterStarPositionP;
}
else
{
return false;
}
}
}
while(*p=='*')
{
p++;
}
if(*p=='\0') return true;
else return false;
}
};
【leetcode】Wildcard Matching的更多相关文章
- 【leetcode】Wildcard Matching(hard) ★ 大神太牛了
Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any single character. ...
- 【LeetCode】字符串 string(共112题)
[3]Longest Substring Without Repeating Characters (2019年1月22日,复习) [5]Longest Palindromic Substring ( ...
- 【LeetCode】回溯法 backtracking(共39题)
[10]Regular Expression Matching [17]Letter Combinations of a Phone Number [22]Generate Parentheses ( ...
- 【LeetCode】贪心 greedy(共38题)
[44]Wildcard Matching [45]Jump Game II (2018年11月28日,算法群衍生题) 题目背景和 55 一样的,问我能到达最后一个index的话,最少走几步. 题解: ...
- 【leetcode】44. Wildcard Matching
题目如下: 解题思路:本题和[leetcode]97. Interleaving String非常相似,同样可以采用动态规划的方法.记dp[i][j] = 1或者0 表示pattern[0:i]是否匹 ...
- 【LeetCode】792. Number of Matching Subsequences 解题报告(Python)
[LeetCode]792. Number of Matching Subsequences 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://f ...
- 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java
[LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...
- 【Leetcode】Pascal's Triangle II
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3 ...
- 53. Maximum Subarray【leetcode】
53. Maximum Subarray[leetcode] Find the contiguous subarray within an array (containing at least one ...
随机推荐
- Spring MVC启动过程
org.springframework.web.context.ContextLoaderListener ContextLoaderListener的作用就是启动Web容器时,自动装配Applica ...
- [FMX] Android APP 启动黑屏优化补丁
使用说明 *************************************************** Android APP 启动黑屏优化补丁 作者: Swish, YangYxd 201 ...
- C-结构体、枚举
#include <stdio.h> //结构体:可以由多个不同类型的数据构成 int main() { struct Person { //里面的3个变量,可以称为是结构体的成员或者属性 ...
- tmux常用命令
tmux命令可以启动一个tmux服务,tmux服务包含多个session,session包含多个window,window包含多个pane. 常用命令tmux ls #显示已有tmux列表(C-b s ...
- AngularJS启动过程分析
1111 app.controller('myCtrl',['$scope',function($scope){ $scope.wcrq=1234567890; }]); angular.bo ...
- php页面防重复提交方法总结
1.提交按钮置disabled 当用户提交后,立即把按钮置为不可用状态.这种用js来实现. 提交前 复制代码 代码如下: $("#submit").attr('di ...
- rational rose 顺序图的消息加数字
主菜单——〉“Tools”——〉“Options”,在弹出的窗口中选择“Diagram”标签-->display-->sequence numbering
- Mastering Web Application Development with AngularJS 读书笔记(一)
第一章笔记 (一) 一.PS:运行时配置IIS <html> <head> <script src="angular.js"></scri ...
- HDU 2014
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> typedef float ElementType; void Select_Sort ...
- java练手 韩信点兵
Problem C 韩信点兵 时间限制:3000 ms | 内存限制:65535 KB 描述 相传韩信才智过人,从不直接清点自己军队的人数,只要让士兵先后以三人一排.五人一排.七人一排地变换队 ...