mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-02-06 17:40:55 +00:00
add some doctests to algos in backtracking
This commit is contained in:
parent
e9e7c96465
commit
f9fe6cc9a6
|
@ -64,6 +64,10 @@ def generate_parenthesis(n: int) -> list[str]:
|
|||
Example 2:
|
||||
>>> generate_parenthesis(1)
|
||||
['()']
|
||||
|
||||
Example 3:
|
||||
>>> generate_parenthesis(0)
|
||||
['']
|
||||
"""
|
||||
|
||||
result: list[str] = []
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user