Leetcode617 Merge Two Binary Trees
Posted chason95
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Leetcode617 Merge Two Binary Trees相关的知识,希望对你有一定的参考价值。
一道以前用python做过的题,竟然还是迷了…不过最后还是做出来了。
public TreeNode mergeTrees(TreeNode t1, TreeNode t2) { if(t1==null&&t2==null) return null; else if(t1!=null&&t2==null) return t1; else if(t1==null&&t2!=null) return t2; else { TreeNode t =new TreeNode(t1.val+t2.val); t.left=mergeTrees(t1.left,t2.left); t.right=mergeTrees(t1.right,t2.right); return t; } }
以上是关于Leetcode617 Merge Two Binary Trees的主要内容,如果未能解决你的问题,请参考以下文章
[LeetCode] 617. Merge Two Binary Trees
LeetCode(617) Merge Two Binary Trees
Leetcode_easy617. Merge Two Binary Trees
leetcode No617. Merge Two Binary Trees