urlname
type
Post
password
SyncToConfluence
category
Leetcode
date
Apr 9, 2024
slug
01HV0X2N9RHTZJJMBZZXJ026N8
icon
Button
catalog
summary
tags
二叉树
Algorithm
递归
深搜
cover
Status
BusyTime
Status 1
status
Published
题目链接
关键词
- 递归
- 二叉树
解析
- 前提:
- original和cloned两棵树一模一样,只有节点引用不一样
- 树中没有值相同的节点
- target是original中的一个节点
- 思路:
- 两棵树一模一样,可以一起做遍历
- 当遍历到的节点值等于target的值时,此时cloned也遍历到该值所在的节点,直接返回cloned
- 如果节点为null,说明当前分支没有,直接返回null
- 按照上面的思路,对左右子树分别进行查询即可
代码
- Author:CoderWdd
- URL:https://www.wuinsights.top//article/01HV0X2N9RHTZJJMBZZXJ026N8
- Copyright:All articles in this blog, except for special statements, adopt BY-NC-SA agreement. Please indicate the source!
Relate Posts