Skip to content

Commit 7e4b60b

Browse files
mozart-maiapre-commit-ci[bot]MaximSmolskiy
authored
add some doctests to algos in backtracking (#11911)
* add some doctests to algos in backtracking * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Maxim Smolskiy <mithridatus@mail.ru>
1 parent a2efba5 commit 7e4b60b

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

backtracking/generate_parentheses.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ def generate_parenthesis(n: int) -> list[str]:
6464
Example 2:
6565
>>> generate_parenthesis(1)
6666
['()']
67+
68+
Example 3:
69+
>>> generate_parenthesis(0)
70+
['']
6771
"""
6872

6973
result: list[str] = []

backtracking/n_queens.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ def is_safe(board: list[list[int]], row: int, column: int) -> bool:
3333
False
3434
>>> is_safe([[0, 0, 1], [0, 0, 0], [0, 0, 0]], 1, 1)
3535
False
36+
>>> is_safe([[1, 0, 0], [0, 0, 0], [0, 0, 0]], 1, 2)
37+
True
38+
>>> is_safe([[1, 0, 0], [0, 0, 0], [0, 0, 0]], 2, 1)
39+
True
40+
>>> is_safe([[0, 0, 0], [1, 0, 0], [0, 0, 0]], 0, 2)
41+
True
42+
>>> is_safe([[0, 0, 0], [1, 0, 0], [0, 0, 0]], 2, 2)
43+
True
3644
"""
3745

3846
n = len(board) # Size of the board

backtracking/word_break.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ def word_break(input_string: str, word_dict: set[str]) -> bool:
6666
6767
>>> word_break("catsandog", {"cats", "dog", "sand", "and", "cat"})
6868
False
69+
70+
>>> word_break("applepenapple", {})
71+
False
6972
"""
7073

7174
return backtrack(input_string, word_dict, 0)

0 commit comments

Comments
 (0)