LeetCode problem 10: Regular Expression Matching
Posted nosaferyao
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LeetCode problem 10: Regular Expression Matching相关的知识,希望对你有一定的参考价值。
class Solution { public: bool match(string s, string p, int ss, int ps){ int psize = p.size(); int ssize = s.size(); while (ps < psize && ss < ssize){ char c = p[ps]; if (c != ‘.‘ && c != ‘*‘){ if (c != s[ss]){ return false; } ps ++; ss ++; continue; } if (c == ‘*‘){ if (ps == 0){ return false; } char p_last = s[ps-1]; if (p_last == ‘.‘){ p_last = s[ss-1]; } int sss = ss; while (sss < ssize && p_last == s[sss]){ if (match(s, p, ++sss, ps+1)){ return true; } } } ss ++; ps ++; } return (ps == psize && ss == ssize); } bool isMatch(string s, string p) { return match(s, p, 0, 0); } };
以上是关于LeetCode problem 10: Regular Expression Matching的主要内容,如果未能解决你的问题,请参考以下文章
[LeetCode&Python] Problem 504. Base 7
leetcode problem 8: String to Integer (atoi)
https://leetcode-cn.com/problems/roman-to-integer/submissions/