MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / checkBlock

Method checkBlock

java/0036-valid-sudoku.java:49–72  ·  view source on GitHub ↗
(int idxI, int idxJ, char[][] board)

Source from the content-addressed store, hash-verified

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}

Callers 1

isValidSudokuMethod · 0.95

Calls 2

containsMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected