Skip to content

Commit 26e33d8

Browse files
committedOct 5, 2023
fix: issue TheAlgorithms#9844
1 parent b7ab5fb commit 26e33d8

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed
 

Diff for: ‎backtracking/match_word_pattern.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,17 @@ def match_word_pattern(pattern: str, input_string: str) -> bool:
1616
False
1717
"""
1818

19-
def backtrack(pattern_index, str_index):
19+
def backtrack(pattern_index: int, str_index: int) -> bool:
20+
"""
21+
>>> backtrack(0, 0)
22+
True
23+
24+
>>> backtrack(0, 1)
25+
True
26+
27+
>>> backtrack(0, 4)
28+
False
29+
"""
2030
if pattern_index == len(pattern) and str_index == len(input_string):
2131
return True
2232
if pattern_index == len(pattern) or str_index == len(input_string):
@@ -39,13 +49,11 @@ def backtrack(pattern_index, str_index):
3949
del pattern_map[char]
4050
del str_map[substr]
4151
return False
42-
4352
pattern_map: dict[str, str] = {}
4453
str_map: dict[str, str] = {}
4554
return backtrack(0, 0)
4655

4756

4857
if __name__ == "__main__":
4958
import doctest
50-
5159
doctest.testmod()

0 commit comments

Comments
 (0)
Please sign in to comment.