Skip to content

Commit ee21b78

Browse files
authored
Soduko-solver.java (#356)
Here's an solution to the opened issue
1 parent 76b0f81 commit ee21b78

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

Soduko-solver.java

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
class Solution {
2+
public void solveSudoku(char[][] board)
3+
{
4+
solvsss(board);
5+
}
6+
public boolean solvsss(char[][] board)
7+
{
8+
for(int i=0;i<board.length;i++)
9+
{
10+
for(int j=0;j<board[i].length;j++)
11+
{
12+
if(board[i][j]=='.')
13+
{
14+
for(char c='1';c<='9';c++)
15+
{
16+
if(isValidSolv(board,i,j,c))
17+
{
18+
board[i][j]=c;
19+
if(solvsss(board)==true)
20+
{
21+
return true;
22+
}
23+
else
24+
{
25+
board[i][j]='.';
26+
}
27+
}
28+
}
29+
return false;
30+
}
31+
}
32+
}
33+
return true;
34+
35+
}
36+
public boolean isValidSolv(char[][] board,int row,int col,char c)
37+
{
38+
for(int i=0;i<9;i++)
39+
{
40+
if(board[row][i]==c)
41+
{
42+
return false;
43+
}
44+
else if(board[i][col]==c)
45+
{
46+
return false;
47+
}
48+
else if(board[3 * (row / 3) + i / 3][3 * (col / 3) + i % 3] == c)
49+
{
50+
return false;
51+
}
52+
}
53+
return true;
54+
}
55+
}

0 commit comments

Comments
 (0)