LintCode 3690 Clone Binary Tree II (二叉树构建好题)

3690 · Clone Binary Tree II
Algorithms
Medium
Accepted Rate
64%

Description
Solution3
Notes
Discuss
Leaderboard
Record

Description
You are given a binary tree where each node in the tree contains an additional random pointer that can point to any node in the tree or to null.

Please return a deep copy of the tree.

Deep copy

A reference object consists, in general, of two parts: a named Handle, which is what we call a declaration (e.g., a variable), and an internal (unnamed) object, which is the internal object named Handle. It is allocated in the Manged Heap and is typically created by the New method of the newly referenced object.

A deep copy is one in which the source and copy objects are independent of each other, so that changes to either object do not affect the other.

The input form of the tree is the same as a normal binary tree, with each node represented by [val, randomIndex]:

val: Represents the value of the node
randomIndex: The subscript of the node (in the input tree array) pointed to by the random pointer; null if it does not point to any node
The tree is given in the form of the RandomTreeNode class, and similarly you need to return the cloned obtained tree in the form of the RandomTreeNode class.
The range of the number of nodes in a binary tree is
[
0
,
1000
]
[0,1000].

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值