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

Method dfs

java/0427-construct-quad-tree.java:10–28  ·  view source on GitHub ↗
(int row, int column, int n)

Source from the content-addressed store, hash-verified

8 }
9
10 private Node dfs(int row, int column, int n) {
11 Node node = new Node();
12
13 if (areAllEqual(row, column, n)) {
14 node.isLeaf = true;
15 node.val = grid[row][column] == 1;
16 } else {
17 n /= 2;
18 node.isLeaf = false;
19 node.val = false;
20
21 node.topLeft = dfs(row, column, n);
22 node.bottomLeft = dfs(row + n, column, n);
23 node.topRight = dfs(row, column + n, n);
24 node.bottomRight = dfs(row + n, column + n, n);
25 }
26
27 return node;
28 }
29
30 private boolean areAllEqual(int row, int column, int n) {
31 for (int i = 0; i < n; i++) {

Callers 1

constructMethod · 0.95

Calls 1

areAllEqualMethod · 0.95

Tested by

no test coverage detected