Skip to content

Latest commit

 

History

History
31 lines (21 loc) · 706 Bytes

Minimum Absolute Difference in BST.md

File metadata and controls

31 lines (21 loc) · 706 Bytes
 void inorder(Node* root,vector<int> & ans)
    {
        if(root==NULL)
            return;
            
        inorder(root->left,ans);
        ans.push_back(root->data);
        inorder(root->right,ans);
        
    }
    int absolute_diff(Node *root)
    {
        //Your code he
        
        vector<int>ans;
        
        inorder(root,ans);
        
        int a = INT_MAX;
        
        for(int i=0;i<ans.size()-1;i++)
                a = min(a,abs(ans[i]-ans[i+1]));
                
        return a;
    }