Files
exams/algorithms/labs/lab7/leetcode/1/solution.py
2025-10-01 22:55:09 +03:00

27 lines
646 B
Python

from typing import List
class Solution:
def isMatch(self, s: str, p: str) -> bool:
i = j = 0
star = -1
match = 0
n, m = len(s), len(p)
while i < n:
if j < m and (p[j] == s[i] or p[j] == "?"):
i += 1
j += 1
elif j < m and p[j] == "*":
star = j
match = i
j += 1
elif star != -1:
j = star + 1
match += 1
i = match
else:
return False
while j < m and p[j] == "*":
j += 1
return j == m