Concise solution


#1
int Solution::solve(TreeNode* A, TreeNode* B)
{
    if(A == NULL || B == NULL)
        return 0;
    if(A->val == B->val)
        return solve(A->left, B->left) + solve(A->right, B->right) + A->val;
    else if(A->val > B->val)
        return solve(A->left, B) + solve(A, B->right) - solve(A->left, B->right);
    else
        return solve(A, B->left) + solve(A->right, B) - solve(A->right, B->left);
}