forked from Midway91/HactoberFest2023
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathm color painting
55 lines (49 loc) · 1.02 KB
/
m color painting
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
class Solution {
public:
bool isvalid(vector<vector<char>>board,char x,int r,int c){
for(int i=0;i<9;i++){
if(board[r][i]==x){
return false;
}
}
for(int i=0;i<9;i++){
if(board[i][c]==x){
return false;
}
}
for(int i=r/3*3;i<(r/3+1)*3;i++){
for(int j=c/3*3;j<(c/3+1)*3;j++){
if(board[i][j]==x){
return false;
}
}
}
return true;
}
bool solveSud(vector<vector<char>>&board,int row,int col){
for(int i=0;i<row;i++){
for(int j=0;j<col;j++){
if(board[i][j]=='.'){
for(char c='1';c<='9';c++){
if(isvalid(board,c,i,j)==true){
board[i][j]=c;
if(solveSud(board,row,col)==true){
return true;
}
board[i][j]='.';
}
}
return false;
}
}
}
return true;
}
void solveSudoku(vector<vector<char>>& board) {
int r=board.size();
int c=board[0].size();
cout<<r<<c<<" ";
bool solve=solveSud(board,9,9);
return ;
}
};