JavaScript DFS Solution


  • 0
    var minDepth = function(root) {
        if(!root) return 0;
        var result;
        function minHeight(root, depth){
            if(!root.left && !root.right){
                result = Math.min(result || depth, depth)
            }
            if(root.left) minHeight(root.left, depth + 1);
            if(root.right) minHeight(root.right, depth + 1);
        }
        minHeight(root, 1);
        return result;
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.