Skip to content

Commit b6bcb38

Browse files
Update dynamic_programming/wildcard_pattern_matching.r
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent e307c59 commit b6bcb38

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

dynamic_programming/wildcard_pattern_matching.r

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ isMatch_optimized <- function(text, pattern) {
6363
}
6464
}
6565

66+
# Early return for empty text
67+
if (m == 0) {
68+
return(prev[n + 1])
69+
}
70+
6671
for (i in 2:(m + 1)) {
6772
curr <- rep(FALSE, n + 1)
6873
text_char <- substr(text, i - 1, i - 1)

0 commit comments

Comments
 (0)