http://oj.leetcode.com/problems/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 |
思路:
关键在于'*'的处理。对于类似于"a*"的情况,我们可以匹配0个'a',也可以匹配尽可能多的'a'。
1 class Solution { 2 public: 3 bool isMatch(const char *s, const char *p) { 4 if ('