Skip to content

Add arrays/sudoku_solver.py #10623

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 17, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Oct 16, 2023
commit 3a0970cb9ea63cbb7bba4446f1f5b93d364765bf
11 changes: 4 additions & 7 deletions data_structures/arrays/sudoku_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@ class Solution:
def solveSudoku(self, board: List[List[str]]) -> None:
n = 9


def isValid(row, col, ch):
row, col = int(row), int(col)

for i in range(9):

if board[i][col] == ch:
return False
if board[row][i] == ch:
return False

if board[3*(row//3) + i//3][3*(col//3) + i%3] == ch:
if board[3 * (row // 3) + i // 3][3 * (col // 3) + i % 3] == ch:
return False

return True
Expand All @@ -22,7 +20,7 @@ def solve(row, col):
if row == n:
return True
if col == n:
return solve(row+1, 0)
return solve(row + 1, 0)

if board[row][col] == ".":
for i in range(1, 10):
Expand All @@ -37,8 +35,7 @@ def solve(row, col):
else:
return solve(row, col + 1)



solve(0, 0)

#do upvote if it helps.

# do upvote if it helps.