lintcode 375 克隆二叉树
来源:互联网 发布:excel列找出重复数据 编辑:程序博客网 时间:2024/05/22 16:51
1.给定一个二叉树,返回一个他的 克隆品 。
2.创建一个新的根节点,赋值给节点,然后在相同的位置赋给相同的值
3./**
* Definition of TreeNode:
* class TreeNode {
* public:
* int val;
* TreeNode *left, *right;
* TreeNode(int val) {
* this->val = val;
* this->left = this->right = NULL;
* }
* }
*/
class Solution {
public:
/**
* @param root: The root of binary tree
* @return root of new tree
*/
TreeNode* cloneTree(TreeNode *root) {
// Write your code here
if(root==NULL)return root;
TreeNode*newnode=new TreeNode;
if(root!=NULL)
{
if(root->val)newnode->val=root->val;
if(root->left!=NULL) newnode->left=cloneTree(root->left);
if(root->right!=NULL) newnode->right=cloneTree(root->right);
}
return newnode;
}
};
4.题目比较简单,能看懂,就是在相同的位置赋予相同的值
- lintcode 375 克隆二叉树
- LintCode:克隆二叉树
- lintcode,克隆二叉树
- lintcode | 克隆二叉树
- LintCode-克隆二叉树
- LintCode 克隆二叉树
- 克隆二叉树-LintCode
- Lintcode 克隆二叉树
- LintCode 克隆二叉树
- lintcode -- 克隆二叉树
- lintcode:克隆二叉树
- 克隆二叉树-LintCode
- [LintCode]375.克隆二叉树
- lintcode——克隆二叉树
- 375 -二叉树的克隆
- LintCode算法题解——判断数独是否合法、平面列表、克隆二叉树、序列排号
- 二叉树的克隆
- 克隆二叉树
- my-mind在线思维导图软件
- ajax提交整个表单的快捷方式
- 河南工业大学2017“玲珑杯”程序设计竞赛 04
- IIC设备驱动程序(一)————IIC设备的总线及其协议
- HTTP Status 406 – Not Acceptable
- lintcode 375 克隆二叉树
- apply(对象,数组) ,call(对象,变量a,变量b)
- code[vs] 3027线段覆盖2
- Java单例防反序列化,防反射,防clone
- MySql
- Xlistview上拉加载 下拉刷新
- lintcode 453 将二叉树拆分成链表
- ThreadLocal源码解析(二)
- 如何才能用微信进行英语课程的预约