This works on LeetCode but not on Interview Bit


#1
/**
 * Definition for binary tree
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
  TreeNode* solve(TreeNode* root1, TreeNode* root2)
    {
        TreeNode *ans = NULL;
        if(!root1 && !root2)
        {
            return NULL;
        }
        
        else if(!root1)
        {
            ans = new TreeNode(root2->val);    
            ans->left = solve(NULL,root2->left);
            ans->right = solve(NULL,root2->right);  
        }
        else if(!root2)
        {
            ans = new TreeNode(root1->val);
            ans->left = solve(root1->left,NULL);
            ans->right = solve(root1->right,NULL);  
        }
        else{
            ans = new TreeNode(root1->val+root2->val);
            ans->left = solve(root1->left,root2->left);
            ans->right = solve(root1->right,root2->right);  
        } 
        return ans;
    }
TreeNode* Solution::solve(TreeNode* root1, TreeNode* root2) {
       return solve(root1,root2);
}