(int idxI, int idxJ, char[][] board)
| 47 | } |
| 48 | |
| 49 | public boolean checkBlock(int idxI, int idxJ, char[][] board) { |
| 50 | Set<Character> blockSet = new HashSet<>(); |
| 51 | //if idxI = 3 and indJ = 0 |
| 52 | //rows = 6 and cols = 3 |
| 53 | int rows = idxI + 3; |
| 54 | int cols = idxJ + 3; |
| 55 | //and because i initializes to idxI but only goes to rows, we loop 3 times (once for each row) |
| 56 | for (int i = idxI; i < rows; i++) { |
| 57 | //same for columns |
| 58 | for (int j = idxJ; j < cols; j++) { |
| 59 | if (board[i][j] == '.') { |
| 60 | continue; |
| 61 | } |
| 62 | |
| 63 | if (blockSet.contains(board[i][j])) { |
| 64 | return false; |
| 65 | } |
| 66 | |
| 67 | blockSet.add(board[i][j]); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | return true; |
| 72 | } |
| 73 | } |
no test coverage detected