<p>Given the <code>root</code> of a Binary Search Tree (BST), return <em>the minimum absolute difference between the values of any two different nodes in the tree</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/05/bst1.jpg" style="width: 292px; height: 301px;" />
<pre>
<strong>Input:</strong> root = [4,2,6,1,3]
<strong>Output:</strong> 1
</pre>

<p><strong class="example">Example 2:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/05/bst2.jpg" style="width: 282px; height: 301px;" />
<pre>
<strong>Input:</strong> root = [1,0,48,null,null,12,49]
<strong>Output:</strong> 1
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li>The number of nodes in the tree is in the range <code>[2, 10<sup>4</sup>]</code>.</li>
	<li><code>0 &lt;= Node.val &lt;= 10<sup>5</sup></code></li>
</ul>

<p>&nbsp;</p>
<p><strong>Note:</strong> This question is the same as 783: <a href="https://leetcode.com/problems/minimum-distance-between-bst-nodes/" target="_blank">https://leetcode.com/problems/minimum-distance-between-bst-nodes/</a></p>

/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    int leftrightest(TreeNode* root){
        if(root->right==NULL){
            return root->val;
        }

        return leftrightest(root->right);
    }
     int rightleftest(TreeNode* root){
        if(root->left==NULL){
            return root->val;
        }

        return rightleftest(root->left);
    }
    int getMinimumDifference(TreeNode* root) {
        if(root==NULL || (root->right==NULL && root->left==NULL)){
            return INT_MAX;
        }

        int left=INT_MAX, right=INT_MAX;
        int diff1=INT_MAX, diff2=INT_MAX;
        int leftest=INT_MAX, righest=INT_MAX;
        if(root->left != NULL){
                left=getMinimumDifference(root->left);
                diff1= root->val-root->left->val;
                leftest=root->val-leftrightest(root->left);

        } 
        diff1=min(diff1, leftest);
        if(root->right!=NULL) {
            right=getMinimumDifference(root->right);
                diff2= root->right->val-root->val;
                righest=rightleftest(root->right)-root->val;

        }
        diff2=min(diff2, righest);

        return min(diff1 , min(diff2 , min(left,right)));

    }
};
23800