LeetCode_Regular Expression Matching
2013-08-03 17:24
288 查看
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) { // Start typing your C/C++ solution below // DO NOT write int main() function assert(s != NULL && p != NULL); if(*p == '\0') return *s == '\0'; 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++; //匹配多个 } //while 结束后,和*后的进行匹配 return isMatch(s, p+2) ; } } };
/article/6711068.html
相关文章推荐
- LeetCode 10 Regular Expression Matching
- python写算法题:leetcode: 10. Regular Expression Matching
- leetcode: Regular Expression Matching
- leetcode解题报告:10 Regular Expression Matching
- leetcode题解c++ | 10. Regular Expression Matching
- Leetcode-Regular Expression Matching
- leetcode 第10题 Regular Expression Matching
- Leetcode: 10. Regular Expression Matching
- [leetcode] Regular Expression Matching
- leetcode-10 Regular Expression Matching
- 判断正则表达式是否匹配 Regular Expression Matching @LeetCode
- LeetCode | Regular Expression Matching
- leetcode 10 -- Regular Expression Matching
- 140_leetcode_Regular Expression Matching
- LeetCode 10: Regular Expression Matching
- LeetCode--Regular Expression Matching
- Regular Expression Matching - LeetCode
- [Leetcode 10, Hard] Regular Expression Matching
- leetcode — regular-expression-matching
- leetcode题解||Regular Expression Matching 问题