-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathValidSudoko.java
More file actions
38 lines (32 loc) · 1.1 KB
/
ValidSudoko.java
File metadata and controls
38 lines (32 loc) · 1.1 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
package leetcode;
public class ValidSudoko {
public boolean isValidSudoku(char[][] board) {
// Note: The Solution object is instantiated only once and is reused by each test case.
if(board.length == 0)
return false;
boolean[][] row = new boolean[9][9];
boolean[][] column = new boolean[9][9];
boolean[][] block = new boolean[9][9];
for(int i = 0; i < 9; i++){
for(int j = 0; j < 9; j++){
row[i][j] = false;
column[i][j] = false;
block[i][j] = false;
}
}
for(int i = 0; i < 9; i++){
for(int j = 0; j < 9; j++){
if(board[i][j] == '.')
continue;
int c = board[i][j] - '1';
if(row[i][c] || column[j][c] || block[i+j/3][c])
return false;
row[i][c] = column[j][c] = block[i+j/3][c] = true;
}
}
return true;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}