Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created January 3, 2018 08:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jianminchen/009d5636db4c2c0937e4b48dddeb92de to your computer and use it in GitHub Desktop.
Save jianminchen/009d5636db4c2c0937e4b48dddeb92de to your computer and use it in GitHub Desktop.
Julia code analysis - redundant analysis
Input:
Tree 1 Tree 2
1 2
/ \ / \
3 2 1 3
/ \ \
5 4 7
Output:
Merged tree:
3
/ \
4 5
/ \ \
5 4 7
root -> both of null
11:59 pm
binary tree ->
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
Node MergeTwoTree(Node root1, Node root2)
{
if(root1 == null || root2 == null)
{
return null;
}
if(root1 == null)
{
return MergeTwoTree(root2, root1);
}
if(root2 == null)
{
return root1;
}
// base case
root1.val += root2.val;
var rootLeft = MergeTwoTree(root1.left, root2.left);
var rootRight = MergeTwoTree(root2.right, root2.right);
root1.left = rootLeft;
root1.right = rootRight;
return root1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment