TheAlgorithms-C/leetcode/src/617.c
leoperd 83d3234fe2 Update BubbleSort.c (#343)
Update BubbleSort.c
2019-10-12 15:40:42 +05:30

17 lines
640 B
C

struct TreeNode * newNode (int item) {
struct TreeNode *node = (struct TreeNode *)malloc(sizeof(struct TreeNode));
node->val = item;
node->left = node->right = NULL;
return node;
}
struct TreeNode* mergeTrees(struct TreeNode* t1, struct TreeNode* t2){
if (t1 == NULL && t2 == NULL)
return NULL;
int item = (t1 == NULL ? 0 : t1->val) + (t2 == NULL ? 0 : t2->val);
struct TreeNode *node = newNode(item);
node->left = mergeTrees(t1 == NULL ? NULL : t1->left, t2 == NULL ? NULL : t2->left);
node->right = mergeTrees(t1 == NULL ? NULL : t1->right, t2 == NULL ? NULL : t2->right);
return node;
}