| 1 | class Solution { |
| 2 | public boolean isValidSudoku(char[][] board) { |
| 3 | HashMap[] row = new HashMap[9]; |
| 4 | HashMap[] column = new HashMap[9]; |
| 5 | HashMap[] box = new HashMap[9]; |
| 6 | for (int i = 0; i < 9; i++) { |
| 7 | row[i] = new HashMap(9); |
| 8 | column[i] = new HashMap(9); |
| 9 | box[i] = new HashMap(9); |
| 10 | } |
| 11 | for (int i = 0; i < 9; i++) { |
| 12 | for (int j = 0; j < 9; j++) { |
| 13 | if (board[i][j] == '.') { |
| 14 | continue; |
| 15 | } |
| 16 | int boxIndex=i / 3 * 3 + j / 3; |
| 17 | if ((boolean) row[i].getOrDefault(board[i][j], true)) { |
| 18 | return false; |
| 19 | } |
| 20 | if ((boolean) column[j].getOrDefault(board[i][j], true)) { |
| 21 | return false; |
| 22 | } |
| 23 | if ((boolean) box[boxIndex].getOrDefault(board[i][j], true)) { |
| 24 | return false; |
| 25 | } |
| 26 | row[i].put(board[i][j], false); |
| 27 | column[j].put(board[i][j], false); |
| 28 | box[boxIndex].put(board[i][j], false); |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | return true; |
| 33 | } |
| 34 | } |
nothing calls this directly
no outgoing calls
no test coverage detected