Javascript Solution - DFS In-Order && O(1) Space


  • 0
    G
    var getMinimumDifference = function(root) {
        var prev = Infinity;
        var totalMin = Infinity;
        
        function traverse(node) {
            if (!node) {
                return;
            }
            
            traverse(node.left);
            
            totalMin = Math.min(totalMin, Math.abs(node.val - prev));
            prev = node.val;
            
            traverse(node.right);
        }
        
        traverse(root);
        
        return totalMin;
    };
    

Log in to reply
 

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