Maximum Depth of Binary Tree | LeetCode 104 | Google Coding Interview Tutorial

Sdílet
Vložit
  • čas přidán 7. 09. 2024

Komentáře • 7

  • @TerribleWhiteboard
    @TerribleWhiteboard  Před 4 lety +8

    If there are any videos you'd like me to make or if you have any ideas on how to optimize this solution, let me know!

  • @lennythach607
    @lennythach607 Před 2 lety

    Out of all of the solutions, this one made the most sense to me! Thanks for the vid!

  • @akashpurushotham2278
    @akashpurushotham2278 Před 2 lety

    I'm enjoying your whiteboard solutions so much.💖

  • @firefly96863
    @firefly96863 Před 2 lety

    great videos! your leetcode solutions are very helpful!

  • @shadmanmartinpiyal4057

    // following solution is identical to the solution of the "Balanced binary tree"
    var maxDepth = function(root) {
    if(!root) return 0;
    function getHeight(node){
    if(!node) return 0;
    let left = getHeight(node.left)
    let right = getHeight(node.right)
    return Math.max(left, right) + 1
    }
    return getHeight(root)
    };