Skip to content

Commit

Permalink
Merge pull request #97 from ritikpatel17/patch-1
Browse files Browse the repository at this point in the history
Regular Expression Matching
  • Loading branch information
avastino7 authored Nov 1, 2022
2 parents 1c2f785 + 782dac2 commit f6ab578
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions isMatch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution(object):
def isMatch(self, text, pattern):
"""
:type text: str
:type pattern: str
:rtype: bool
"""
if not pattern:
return not text

first_match = bool(text) and pattern[0] in {text[0], '.'}

if len(pattern) >= 2 and pattern[1] == '*':
return (self.isMatch(text, pattern[2:]) or
first_match and self.isMatch(text[1:], pattern))
else:
return first_match and self.isMatch(text[1:], pattern[1:])

0 comments on commit f6ab578

Please sign in to comment.