Leetcode 之Regular Expression Matching(31)

正则表达式的匹配,还是挺难的。可根据下一个字符是不是*分为两种情况处理,需要考虑多种情况。
bool isMatch(const char *s, const char *p)
{
if (*p == '\0')return *s == '\0'; //如果下一个不是*(*可表示前一个字符的数量)
//要么当前字符匹配,要么是.,不可跳过
if (*(p + ) != '*')
{
if (*s == *p || (*p == '.' && *s != '\0'))
return isMatch(s + , p + );
else
return false;
}
else
{
//如果是*,则当前字符匹配|| 有一个为.
//因为后面是*,即使不完全匹配也没关系,跳过即可
while (*p == *s || (*p == '.' && *s != '\0'))
{
if (isMatch(s, p + ))
return true;
s++;
}
return isMatch(s, p + );
}
}
Leetcode 之Regular Expression Matching(31)的更多相关文章
- leetcode 10 Regular Expression Matching(简单正则表达式匹配)
最近代码写的少了,而leetcode一直想做一个python,c/c++解题报告的专题,c/c++一直是我非常喜欢的,c语言编程练习的重要性体现在linux内核编程以及一些大公司算法上机的要求,pyt ...
- LeetCode (10): Regular Expression Matching [HARD]
https://leetcode.com/problems/regular-expression-matching/ [描述] Implement regular expression matchin ...
- [LeetCode][Python]Regular Expression Matching
# -*- coding: utf8 -*-'''https://oj.leetcode.com/problems/regular-expression-matching/ Implement reg ...
- [LeetCode] 10. Regular Expression Matching 正则表达式匹配
Given an input string (s) and a pattern (p), implement regular expression matching with support for ...
- Leetcode 10. Regular Expression Matching(递归,dp)
10. Regular Expression Matching Hard Given an input string (s) and a pattern (p), implement regular ...
- [LeetCode] 10. Regular Expression Matching
Implement regular expression matching with support for '.' and '*'. DP: public class Solution { publ ...
- 【leetcode】Regular Expression Matching
Regular Expression Matching Implement regular expression matching with support for '.' and '*'. '.' ...
- 【leetcode】Regular Expression Matching (hard) ★
Implement regular expression matching with support for '.' and '*'. '.' Matches any single character ...
- 【JAVA、C++】LeetCode 010 Regular Expression Matching
Implement regular expression matching with support for '.' and '*'. '.' Matches any single character ...
- Java [leetcode 10] Regular Expression Matching
问题描述: Implement regular expression matching with support for '.' and '*'. '.' Matches any single cha ...
随机推荐
- 以安装PyTorch为例说明Anaconda在Windows/Linux上的使用
在Windows10上配置完MXNet 1.3.0后,再配置PyTorch 1.0时,发现两者需要依赖的NumPy版本不一致,之前是通过pip安装NumPy,根据pip的版本不同,会安装不同版本的Nu ...
- 分享几款常用的API/文档浏览器
1.Dash 支持平台:Mac iOS 官网:https://kapeli.com/dash 2.Zeal 支持平台:Linux Windows 官网:https://zealdocs.org/ G ...
- HDOJ(HDU).2044-2049 递推专题
HDOJ(HDU).2044-2049 递推专题 点我挑战题目 HDU.2044 题意分析 先考虑递推关系:从1到第n个格子的时候由多少种走法? 如图,当n为下方格子的时候,由于只能向右走,所以有2中 ...
- 从零开始学Linux系统(五)用户管理和权限管理
权限管理: 常识: chmod U-所有者 g-所属组 O-其他人r-4-可读 w-2-可写 x-1-可执行 s-4-SetUID s-2-SetGID t-1-粘着位 注:目 ...
- Hadoop Yarn-入门篇
参考并推荐博文:https://www.ibm.com/developerworks/cn/opensource/os-cn-hadoop-yarn/ 重构根本的思想是将 JobTracker 两个主 ...
- 51nod 1273 旅行计划(思维题)
一开始看到这题真的有点懵逼...一直在想着套算法,结果题解除了sort和dfs其他什么都没用到 显然每次到达的一定都是叶子,先从根节点dfs一遍,按深度对叶子降序排序,按这个顺序向根节点dfs,路径上 ...
- js正则表达式,判断字符串是否以数字组结尾,并取出结尾的数字
js正则表达式,判断字符串是否以数字组结尾,并取出结尾的数字 <!DOCTYPE html> <html> <head> <meta charset=&quo ...
- SFM
1.相机模型,内参数和外参数矩阵,相机标定: 2.极线约束和本征矩阵:特征点提取与匹配:提取到的特征点计算本征矩阵(五对以上的点)findEssentialMat(),需啊要点对,焦距参数,cx,cy ...
- hdu 1698 线段树 区间更新 区间求和
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- Java的位运算符—与(&)、非(~)、或(|)、异或(^)
位运算符主要针对二进制,它包括了:“与”.“非”.“或”.“异或”.从表面上看似乎有点像逻辑运算符,但逻辑运算符是针对两个关系运算符来进行逻辑运算,而位运算符主要针对两个二进制数的位进行逻辑运算.下面 ...