Skip to content

Commit f9fe6cc

Browse files
committed
add some doctests to algos in backtracking
1 parent e9e7c96 commit f9fe6cc

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

backtracking/generate_parentheses.py

+4
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

+8
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ def is_safe(board: list[list[int]], row: int, column: int) -> bool:
2929
True
3030
>>> is_safe([[1, 0, 0], [0, 0, 0], [0, 0, 0]], 1, 1)
3131
False
32+
>>> is_safe([[1, 0, 0], [0, 0, 0], [0, 0, 0]], 1, 2)
33+
True
34+
>>> is_safe([[1, 0, 0], [0, 0, 0], [0, 0, 0]], 2, 1)
35+
True
36+
>>> is_safe([[0, 0, 0], [1, 0, 0], [0, 0, 0]], 0, 2)
37+
True
38+
>>> is_safe([[0, 0, 0], [1, 0, 0], [0, 0, 0]], 2, 2)
39+
True
3240
"""
3341

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

backtracking/word_break.py

+3
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)