-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValidSudoku.cpp
More file actions
executable file
·58 lines (55 loc) · 1.24 KB
/
ValidSudoku.cpp
File metadata and controls
executable file
·58 lines (55 loc) · 1.24 KB
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
56
57
58
//
// ValidSudoku.cpp
// leetcode
//
// Created by witwolf on 4/24/15.
// Copyright (c) 2015 witwolf. All rights reserved.
//
#include <stdio.h>
#include <string.h>
bool vaildFlag(char c,char flags[]){
if(c != '.'){
if(flags[c-'1'] ++){
return false;
}
}
return true;
}
bool isValidSudoku(char board[9][9]) {
char flags[9];
int column,row;
for(column=0;column < 9;++column){
memset(flags, 0, 9);
for(row=0;row<9;++row){
if(!vaildFlag(board[row][column],flags))
return false;
}
memset(flags, 0, 9);
for(row=0;row<9;++row){
if(!vaildFlag( board[column][row],flags))
return false;
}
}
int i = 0;
char rowBases[] = {
0,0,0,
3,3,3,
6,6,6
};
char columnBases[] = {
0,3,6,
0,3,6,
0,3,6
};
for(i=0;i<9;++i){
memset(flags, 0, 9);
int rowBase = rowBases[i],columnBase = columnBases[i];
for(row=0;row<3;++row){
for(column=0;column<3;++column){
if(!vaildFlag( board[rowBase+ row][columnBase+ column],flags))
return false;
}
}
}
return true;
}