maxDepthTuring.js

    0

    0

    In the code, the function maxDepth takes two arguments: a root object and an integer. The functionmaxDepth calculates the maximum depth of the two subtrees rooted at the object passed as the argument, and then returns the value of 1 plus the number of nodes in the deepest subtree.

    function maxDepth(root) {
      if (!root) return 0;
      return Math.max(maxDepth(root.left), maxDepth(root.right)) + 1;
    }
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.