add some doctests to algos in backtracking

This commit is contained in:
Mozart Maia 2024-10-09 01:36:11 -03:00
parent e9e7c96465
commit f9fe6cc9a6
3 changed files with 15 additions and 0 deletions

View File

@ -64,6 +64,10 @@ def generate_parenthesis(n: int) -> list[str]:
Example 2:
>>> generate_parenthesis(1)
['()']
Example 3:
>>> generate_parenthesis(0)
['']
"""
result: list[str] = []

View File

@ -29,6 +29,14 @@ def is_safe(board: list[list[int]], row: int, column: int) -> bool:
True
>>> is_safe([[1, 0, 0], [0, 0, 0], [0, 0, 0]], 1, 1)
False
>>> is_safe([[1, 0, 0], [0, 0, 0], [0, 0, 0]], 1, 2)
True
>>> is_safe([[1, 0, 0], [0, 0, 0], [0, 0, 0]], 2, 1)
True
>>> is_safe([[0, 0, 0], [1, 0, 0], [0, 0, 0]], 0, 2)
True
>>> is_safe([[0, 0, 0], [1, 0, 0], [0, 0, 0]], 2, 2)
True
"""
n = len(board) # Size of the board

View File

@ -66,6 +66,9 @@ def word_break(input_string: str, word_dict: set[str]) -> bool:
>>> word_break("catsandog", {"cats", "dog", "sand", "and", "cat"})
False
>>> word_break("applepenapple", {})
False
"""
return backtrack(input_string, word_dict, 0)