Update dynamic_programming/regex_match.py

Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com>
This commit is contained in:
Amir Hosseini 2023-08-14 08:07:37 +03:30 committed by GitHub
parent c2bd6bf9a2
commit 7271e3d2a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -30,11 +30,8 @@ def recursive_match(text: str, pattern: str) -> bool:
>>> recursive_match('aa', '.*')
True
"""
if not text and not pattern:
return True
if text and not pattern:
return False
if not pattern:
return not text
if not text:
return pattern[-1] == "*" and recursive_match(text, pattern[:-2])