MCPcopy Create free account
hub / github.com/ROUTINE-STUDY/Algorithm / Sanghoo

Class Sanghoo

LeetCode/BFS/559. Maximum Depth of N-ary Tree/Sanghoo.java:24–50  ·  view source on GitHub ↗

https://leetcode.com/problems/maximum-depth-of-n-ary-tree/

Source from the content-addressed store, hash-verified

22 * https://leetcode.com/problems/maximum-depth-of-n-ary-tree/
23 */
24public class Sanghoo {
25
26 public static int maxDepth(Node root) {
27 if(root == null) return 0;
28
29 int res = 0;
30 Queue<Node> q = new LinkedList<>();
31
32 q.offer(root);
33
34 while (!q.isEmpty()) {
35 int size = q.size();
36
37 for(int i=0; i<size; i++) {
38 Node node = q.poll();
39
40 for(Node n : node.children) {
41 q.offer(n);
42 }
43 }
44 res++;
45 }
46
47 return res;
48 }
49
50}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected