375.Clone Binary Tree-克隆二叉树(容易题)
来源:互联网 发布:逆战瞬狙数据 编辑:程序博客网 时间:2024/06/06 06:34
克隆二叉树
题目
深度复制一个二叉树。
给定一个二叉树,返回一个他的 克隆品 。样例
给定一个二叉树:
返回其相同结构相同数值的克隆二叉树:题解
/** * Definition of TreeNode: * public class TreeNode { * public int val; * public TreeNode left, right; * public TreeNode(int val) { * this.val = val; * this.left = this.right = null; * } * } */public class Solution { /** * @param root: The root of binary tree * @return root of new tree */ public TreeNode cloneTree(TreeNode root) { if (root == null) { return root; } TreeNode result = new TreeNode(root.val); result.left = cloneTree(root.left); result.right = cloneTree(root.right); return result; }}
Last Update 2016.9.13
0 0
- 375.Clone Binary Tree-克隆二叉树(容易题)
- 93.Balanced Binary Tree-平衡二叉树(容易题)
- 175.Invert Binary Tree-翻转二叉树(容易题)
- 469.Identical Binary Tree-等价二叉树(容易题)
- 克隆一个有随机指针的二叉树 Clone a Binary Tree with Random Pointers
- 66.Binary Tree Preorder Traversal-二叉树的前序遍历(容易题)
- 67.Binary Tree Inorder Traversal-二叉树的中序遍历(容易题)
- 68.Binary Tree Postorder Traversal-二叉树的后序遍历(容易题)
- 97.Maximum Depth of Binary Tree-二叉树的最大深度(容易题)
- 155.Minimum Depth of Binary Tree-二叉树的最小深度(容易题)
- 480.Binary Tree Paths-二叉树的所有路径(容易题)
- 85.Insert Node in a Binary Search Tree-在二叉查找树中插入节点(容易题)
- 453.Flatten Binary Tree to Linked List-将二叉树拆成链表(容易题)
- 二叉树(binary tree)
- 二叉树(Binary Tree)
- 二叉树(binary tree)
- 177.Convert Sorted Array to Binary Search Tree With Minimal Height-把排序数组转换为高度最小的二叉搜索树(容易题)
- 二叉树Binary Tree
- C++_Primer_chapter17 2.命名空间
- Kinect尝鲜(1)——第一个程序
- linux ifcfg-eth0文件配置静态ip(centos-6.5)
- mongodb remove
- hdu 5877 离散化+树状数组+dfs序
- 375.Clone Binary Tree-克隆二叉树(容易题)
- boost 安装
- 数据库索引的作用优点和缺点
- Java中函数参数的传递是值传递还是引用传递
- 12章 5题
- Spark入门的WordCount
- 12章 1.判断春夏秋冬
- 黑马 ios 技术博客
- mysql install