-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathSalesforce_Solution.cpp
56 lines (55 loc) · 1.12 KB
/
Salesforce_Solution.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Solution by Ankur Gupta.
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl '\n'
struct TreeNode
{
int data;
TreeNode *left;
TreeNode *right;
TreeNode(ll val)
{
data = val;
left = NULL;
right = NULL;
}
};
TreeNode *FindAns(TreeNode *Tree1, TreeNode *Tree2)
{
// Basic idea is we are adding the value of Tree2 in Tree1 and then return Tree1 as the answer
if (Tree1 != NULL && Tree2 != NULL)
{
Tree1->data += Tree2->data;
Tree1->left = FindAns(Tree1->left, Tree2->left);
Tree1->right = FindAns(Tree1->right, Tree2->right);
}
else
{
if (Tree1 != NULL)
{
return Tree1;
}
return Tree2;
}
return Tree1;
}
void solve()
{
// We will take Input From the user
TreeNode *Tree1 = new TreeNode(1);
TreeNode *Tree2 = new TreeNode(1);
// Its just a random input
FindAns(Tree1, Tree2);
// Print(Tree1)
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
// cin >> t;
while (t--)
solve();
return 0;
}