leetcode_010 Regular Expression Matching
来源:互联网 发布:vb序列号 编辑:程序博客网 时间:2024/05/14 04:00
题目分析:
- 给定一个原字符串和一个正则表达式,判断其是否匹配
解题思路:
递归实现
基本思想:一个字符一个字符进行匹配,当遇到特殊字符如’*’和’.’时进行特殊处理。
实现程序
bool isMatch(char *s, char *p){ // 如果字符串p为空,则依据s是否为空返回最后结果 if(*p == '\0') return *s == '\0'; // p的下一个字符不是*时处理 if(*(p + 1) != '*') { // 在 *s = *p 和 *p = '.' 且 *s 不为结束符情况,直接匹配判断p + 1 和 s + 1,直接返回false。 if(*s == *p || (*p == '.' && *s != '\0')) isMatch(s + 1, p + 1); else return false; } // p的下一个字符为*时处理 else { // 在 *s = *p 和 *p = '.' 且 *s 不为结束符情况,匹配判断s 和 p + 2,并做对应处理,否则直接进行 s 和 p + 2 的处理 while(*s == *p || *p == '.' && *s != '\0') { if (isMatch(s, p + 2)) return true; s++; } return isMatch(s, p+2); }}
0 0
- leetcode_010 Regular Expression Matching
- 2017-09-09 LeetCode_010 Regular Expression Matching
- LeetCode: Regular Expression Matching
- LeetCode: Regular Expression Matching
- leetcode Regular Expression Matching
- [Leetcode] Regular Expression Matching
- Regular Expression Matching
- Regular Expression Matching
- [LeetCode]Regular Expression Matching
- Regular Expression Matching
- LeetCode-Regular Expression Matching
- Regular Expression Matching
- Regular Expression Matching LeetCode
- Regular Expression Matching
- LeetCode | Regular Expression Matching
- LeetCode: Regular Expression Matching
- Leetcode: Regular Expression Matching
- [LeetCode] Regular Expression matching
- SpringMVC返回json数据的三种方式
- iOS——图片的两种加载方式
- 1014. 福尔摩斯的约会 分析
- BC#78Div.2 1001
- java动态代理对象实现日志的拦截(annotation自定义注解方式)
- leetcode_010 Regular Expression Matching
- 准确率与召回率
- 题目1013:开门人和关门人
- 两个人走到一起
- JS实现全选、不选、反选
- Struts的Action中获取Request和response对象
- 嵌入式
- Hive表的数据载入方式
- 商人小鑫