MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / check

Function check

javascript/0010-regular-expression-matching.js:65–78  ·  view source on GitHub ↗
(text, pattern, row, col, memo)

Source from the content-addressed store, hash-verified

63 ); /* Time O(M) | Space O(M) */
64
65var check = (text, pattern, row, col, memo) => {
66 const isTextDefined = row < text.length,
67 isTextAndPatternEqual = pattern[col] === text[row],
68 isPatternPeriod = pattern[col] === '.',
69 isFirstMatch =
70 isTextDefined && (isTextAndPatternEqual || isPatternPeriod),
71 isNextPatternWildCard =
72 col + 1 < pattern.length && pattern[col + 1] === '*';
73
74 return isNextPatternWildCard /* Time O(N * M) | Space O(N * M) */
75 ? isMatch(text, pattern, row, col + 2, memo) ||
76 (isFirstMatch && isMatch(text, pattern, row + 1, col, memo))
77 : isFirstMatch && isMatch(text, pattern, row + 1, col + 1, memo);
78};
79
80/**
81 * Time O(N * M) | Space O(N * M)

Callers 1

isMatchFunction · 0.70

Calls 1

isMatchFunction · 0.70

Tested by

no test coverage detected