【leetcode】Regular Expression Matching
Regular Expression Matching
Implement regular expression matching with support for '.' and '*'.
'.' Matches any single character.
'*' Matches zero or more of the preceding element. 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", "a*") → true
isMatch("aa", ".*") → true
isMatch("ab", ".*") → true
isMatch("aab", "c*a*b") → true
class Solution {
public:
bool isMatch(const char *s, const char *p) {
if(s==NULL||p==NULL) return false;
if(*p=='\0'&&*s=='\0') return true;
if(*p=='\0'&&*s!='\0') return false;
//如果模式串下一个字符为*
if(*(p+)=='*')
{
//循环比较当前字符与模式串字符是否相等
while((*s!='\0'&&*p=='.')||(*s==*p))
{
//防止这种情况出现:"aaa", "a*a"
if(isMatch(s,p+)) return true;
s++;
}
return isMatch(s,p+);
}
else if((*s!='\0'&&*p=='.')||*s==*p)
{
//如果当前元素相等,则开始匹配下一个元素
return isMatch(s+,p+);
}
return false;
}
};
【leetcode】Regular Expression Matching的更多相关文章
- 【leetcode】Regular Expression Matching (hard) ★
Implement regular expression matching with support for '.' and '*'. '.' Matches any single character ...
- leetcode 10 Regular Expression Matching(简单正则表达式匹配)
最近代码写的少了,而leetcode一直想做一个python,c/c++解题报告的专题,c/c++一直是我非常喜欢的,c语言编程练习的重要性体现在linux内核编程以及一些大公司算法上机的要求,pyt ...
- 【JAVA、C++】LeetCode 010 Regular Expression Matching
Implement regular expression matching with support for '.' and '*'. '.' Matches any single character ...
- 【leetcode刷题笔记】Regular Expression Matching
Implement regular expression matching with support for '.' and '*'. '.' Matches any single character ...
- LeetCode (10): Regular Expression Matching [HARD]
https://leetcode.com/problems/regular-expression-matching/ [描述] Implement regular expression matchin ...
- [leetcode]10. Regular Expression Matching正则表达式的匹配
Given an input string (s) and a pattern (p), implement regular expression matching with support for ...
- LeetCode之Regular Expression Matching
[题目描述] Implement regular expression matching with support for '.' and '*'. '.' Matches any single ch ...
- [LeetCode][Python]Regular Expression Matching
# -*- coding: utf8 -*-'''https://oj.leetcode.com/problems/regular-expression-matching/ Implement reg ...
- 【LeetCode】44. Wildcard Matching (2 solutions)
Wildcard Matching Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any ...
随机推荐
- Why you shouldn't use Entity Framework with Transactions
Links EntityFramework This is a .net ORM Mapper Framework from Microsoft to help you talking with yo ...
- HDInsight 指定输出目录 insert overwrite
基本语法 insert overwrite local directory '/example/demo/' select * from table; 可以格式化输出 insert overwrite ...
- jquery 中的事件冒泡
废话少说,先来一段代码热热身: <!DOCTYPE html> <html> <head> <title>demo</title> < ...
- C# 拷贝目录
public class DirectoryExtends { /// <summary> /// 拷贝目录 /// </summary> /// <param name ...
- 遍历JObject
JObject jo = JObject.Parse(jsonStr); IEnumerable<JProperty> properties = jo.Properties(); fore ...
- CDN技术
CDN 是构建在数据网络上的一种分布式的内容分发网. CDN 的作用是采用流媒体服务器集群技术,克服单机系统输出带宽及并发能力不足的缺点,可极大提升系统支持的并发流数目,减少或避免单点失效带来的不良影 ...
- linux下的chm阅读器?
pre和code标签是可以同时使用的, 通常pre放在code的前面. 由于 code, pre中不能使用 换行, 段落, 和 尖括号标签, 所以, 对于尖括号, 要换成 html的 实体符号 < ...
- vmstat、top
vmstat是一个查看虚拟内存(Virtual Memory)使用状况的工具,使用vmstat命令可以得到关于进程.内存.内存分页.堵塞IO.traps及CPU活动的信息. vmstat 最常用的有两 ...
- IOS表情存入MYSQL数据库失败
从 MySQL 5.5.3 开始,MySQL 支持一种 utf8mb4 的字符集,这个字符集能够支持 4 字节的 UTF8 编码的字符. utf8mb4 字符集能够完美地向下兼容 utf8 字符串.在 ...
- linq和lanmbda表达式比较解析