Skip to content

Latest commit

 

History

History
33 lines (26 loc) · 699 Bytes

Question_559.md

File metadata and controls

33 lines (26 loc) · 699 Bytes

LeetCode Records - Question 559 Maximum Depth of N-ary Tree

Attempt 1: Use recursion

class Solution {

    private int max = 0;

    public int maxDepth(Node root) {
        if (root == null) {
            return 0;
        }

        maxDepthRecursion(root, 0);
        return max;
    }

    private void maxDepthRecursion(Node root, int currDepth) {
        if (root.children.size() == 0) {
            max = Math.max(max, currDepth + 1);
            return;
        }

        for (Node child : root.children) {
            maxDepthRecursion(child, currDepth + 1);
        }
    }
}
  • Runtime: 0 ms (Beats: 100.00%)
  • Memory: 42.78 MB (Beats: 99.00%)