6 line easy C++ O(N) time complexity without extra space


#1

TreeNode* Solution::solve(TreeNode* A, TreeNode* B) {
if(A and B){
A->val+=B->val;

    A->left=solve(A->left,B->left);
    A->right=solve(A->right,B->right);
    
    return A;
}
else{
    return A?A:B;
}

}