Simple Solution using inorder traversal + one vector scan !!


  • 0
    P

    '''
    class Solution {
    public:

    vector<int > A;
    
    void inorder(TreeNode* root)
    {
        if(root)
        {
            inorder(root->left);
            A.push_back(root->val);
            inorder(root->right);
        }
    }
    
    
    int getMinimumDifference(TreeNode* root) {
        
        
        A.clear();
        int mine=INT_MAX;
        if(root)
            inorder(root);
        for(int i=0;i<A.size()-1;i++)
        {
            mine=min(mine,abs(A[i]-A[i+1]));
        }
        
        return mine;
    }
    

    };
    '''


Log in to reply
 

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