【发布时间】:2021-07-08 04:03:21
【问题描述】:
我正在解决 leetcode 上的正则表达式匹配问题。我使用递归解决了它,如下所示:
if (p.empty()) return s.empty();
if ('*' == p[1])
// x* matches empty string or at least one character: x* -> xx*
// *s is to ensure s is non-empty
return (isMatch(s, p.substr(2)) || !s.empty() && (s[0] == p[0] || '.' == p[0]) && isMatch(s.substr(1), p));
else
return !s.empty() && (s[0] == p[0] || '.' == p[0]) && isMatch(s.substr(1), p.substr(1));
但是在这我怎么能找到代码的时间复杂度呢?
问题链接:https://leetcode.com/problems/regular-expression-matching/
PS:在解决方案中,他们已经解释了时间复杂度,但我无法理解。
【问题讨论】:
标签: c++ algorithm time-complexity