leetcode - Regular Expression Matching
2013-12-16 18:56 张汉生 阅读(176) 评论(0) 编辑 收藏 举报
1 class Solution { 2 public: 3 //http://blog.csdn.net/pickless/article/details/9043389 4 bool isMatch(const char *s, const char *p) { 5 if (*p == '\0'){ 6 return *s == '\0'; 7 } 8 if (*(p + 1) == '*'){ 9 while (*s != '\0' && (*s == *p || *p == '.')){ 10 if (isMatch(s, p + 2)) 11 return true; 12 s++; 13 } 14 return isMatch(s, p + 2); 15 } 16 if (*s != '\0' && (*s == *p || *p == '.')) 17 return isMatch(s + 1, p + 1); 18 return false; 19 } 20 };