LeetCode 题解(13):Regular Expression Matching
来源:互联网 发布:乍得内战知乎 编辑:程序博客网 时间:2024/06/04 01:30
题目:
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") → falseisMatch("aa","aa") → trueisMatch("aaa","aa") → falseisMatch("aa", "a*") → trueisMatch("aa", ".*") → trueisMatch("ab", ".*") → trueisMatch("aab", "c*a*b") → true
题解:
先给出递归做法。正在思索动态规划做法。
class Solution {public: bool isMatch(const char *s, const char *p) { if(!*p) return *s == '\0'; else if(*(p+1) != '*') { if(*s == *p || (*p == '.' && *s != '\0')) return isMatch(s+1, p+1); return false; } else { while(*s == *p || ((*p == '.' && *s != '\0'))) { if(isMatch(s, p+2)) return true; s++; } return isMatch(s, p+2); } }};
0 0
- LeetCode 题解(13):Regular Expression Matching
- LeetCode题解: Regular Expression Matching
- LEETCODE 10 Regular Expression Matching (JAVA题解)
- leetcode题解||Regular Expression Matching 问题
- LeetCode题解--10. Regular Expression Matching
- LeetCode题解-10-Regular Expression Matching
- leetcode题解c++ | 10. Regular Expression Matching
- 10. Regular Expression Matching LeetCode题解
- Leetcode题解---Regular Expression Matching Java实现
- leetcode题解-10. 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
- LeetCode-Regular Expression Matching
- Regular Expression Matching LeetCode
- mapinfo教程
- 代码耦合
- python写的掉空格数字字母的方法
- 输入目录,清除目录下的class文件
- C++多态的灵活运用
- LeetCode 题解(13):Regular Expression Matching
- 0-1背包问题——小P寻宝记
- POJ 1423 Big Number
- 字符串比较——加密术
- 线性表的顺序表示和操作
- SDUT 出现次数
- ZOJ-1057
- 寻找前K大数
- 浏览器与服务器交互信息(序列化与发序列化) ViewState