-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution_36.java
More file actions
54 lines (49 loc) · 1.13 KB
/
Solution_36.java
File metadata and controls
54 lines (49 loc) · 1.13 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
package com.hilbert25.leetcode;
import java.util.BitSet;
/**
* @author : hilbert25
* @version 创建时间:2017年4月10日 上午11:33:40 LeetCode com.hilbert25.leetcode
* Solution_36
*/
public class Solution_36 {
public static void main(String[] args) {
// TODO Auto-generated method stub
}
public boolean isValidSudoku(char[][] board) {
BitSet set = new BitSet(9);
for (int i = 0; i < 9; i++) {
set.clear();
int endm = 3 * (i / 3) + 3;
int endn = 3 * (i % 3) + 3;
for (int m = 3 * (i / 3); m < endm; m++) {
for (int n = 3 * (i % 3); n < endn; n++) {
if (board[m][n] != '.') {
if (set.get(board[m][n] - '1'))
return false;
else
set.set(board[m][n] - '1');
}
}
}
set.clear();
for (int j = 0; j < 9; j++) {
if (board[i][j] != '.') {
if (set.get(board[i][j] - '1'))
return false;
else
set.set(board[i][j] - '1');
}
}
set.clear();
for (int j = 0; j < 9; j++) {
if (board[j][i] != '.') {
if (set.get(board[j][i] - '1'))
return false;
else
set.set(board[j][i] - '1');
}
}
}
return true;
}
}