Maximum Depth of N-ary Tree LeetCode solution in Java
1class Solution {2public int maxDepth(Node root) {3if (root == null) return 0;4int[] max = new int[] {0};5dfs(root, 1, max);6return max[0];7}89public static void dfs(Node root, int depth, int[] max) {10if (depth > max[0]) max[0] = depth;11if (root == null) {12return;13}14++depth;15for (Node n : root.children) dfs(n, depth, max);16}17}