Skip to content

Commit 2677377

Browse files
committed
Fix n-queues problem
1 parent 738253e commit 2677377

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

backtracking/n_queens.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ def is_safe(board: list[list[int]], row: int, column: int) -> bool:
4040
and all(
4141
board[i][j] != 1 for i, j in zip(range(row, -1, -1), range(column, -1, -1))
4242
)
43-
and all(board[i][j] != 1 for i, j in zip(range(row, n), range(column, n)))
44-
and all(board[i][j] != 1 for i, j in zip(range(row, n), range(column, -1, -1)))
43+
and all(board[i][j] != 1 for i, j in zip(range(row, -1, -1), [column] * (row + 1)) )
4544
)
4645

4746

0 commit comments

Comments
 (0)