当前位置: 首页 > news >正文

网站建设维护及使用管理办法91永久免费海外地域网名

网站建设维护及使用管理办法,91永久免费海外地域网名,西安房产信息网,wordpress 外国主题题目链接 Leetcode.1379 找出克隆二叉树中的相同节点 easy 题目描述 给你两棵二叉树,原始树 original和克隆树 cloned,以及一个位于原始树 original中的目标节点 target。 其中,克隆树 cloned是原始树 original的一个 副本 。 请找出在树 …

题目链接

Leetcode.1379 找出克隆二叉树中的相同节点 easy

题目描述

给你两棵二叉树,原始树 original和克隆树 cloned,以及一个位于原始树 original中的目标节点 target

其中,克隆树 cloned是原始树 original的一个 副本 。

请找出在树 cloned中,与 target相同 的节点,并返回对该节点的引用(在 C/C++ 等有指针的语言中返回 节点指针,其他语言返回节点本身)。

注意:你 不能 对两棵二叉树,以及 target 节点进行更改。只能 返回对克隆树 cloned中已有的节点的引用。

示例 1:

在这里插入图片描述

输入: tree = [7,4,3,null,null,6,19], target = 3
输出: 3
解释: 上图画出了树 original 和 cloned。target 节点在树 original 中,用绿色标记。答案是树 cloned 中的黄颜色的节点(其他示例类似)。

示例 2:

在这里插入图片描述

输入: tree = [7], target = 7
输出: 7

示例 3:

在这里插入图片描述

输入: tree = [8,null,6,null,5,null,4,null,3,null,2,null,1], target = 4
输出: 4

提示:

  • 树中节点的数量范围为 [1,104][1, 10^4][1,104]
  • 同一棵树中,没有值相同的节点。
  • target节点是树 original中的一个节点,并且不会是 null

解法:递归

递归遍历 cloned,找到与 target值相同的结点返回即可。

时间复杂度: O(n)O(n)O(n)

C++代码:

class Solution {
public:TreeNode* getTargetCopy(TreeNode* original, TreeNode* cloned, TreeNode* target) {if(cloned == nullptr) return nullptr;if(cloned->val == target->val) return cloned;auto a = getTargetCopy(original,cloned->left,target);if(a != nullptr) return a;else return getTargetCopy(original,cloned->right,target);}
};

Python代码:


class Solution:def getTargetCopy(self, original: TreeNode, cloned: TreeNode, target: TreeNode) -> TreeNode:if cloned == None:return Noneif cloned.val == target.val:return cloneda = self.getTargetCopy(original,cloned.left,target)if a != None:return aelse:return self.getTargetCopy(original,cloned.right,target)   

文章转载自:
http://garden.tsnq.cn
http://retro.tsnq.cn
http://cicatrize.tsnq.cn
http://unpitied.tsnq.cn
http://hemodynamics.tsnq.cn
http://hosier.tsnq.cn
http://timer.tsnq.cn
http://siphonein.tsnq.cn
http://gazer.tsnq.cn
http://seater.tsnq.cn
http://interoffice.tsnq.cn
http://towfish.tsnq.cn
http://afc.tsnq.cn
http://wv.tsnq.cn
http://chordate.tsnq.cn
http://scourge.tsnq.cn
http://mumble.tsnq.cn
http://hundred.tsnq.cn
http://succinylcholine.tsnq.cn
http://pretender.tsnq.cn
http://skyer.tsnq.cn
http://duodenum.tsnq.cn
http://tavarish.tsnq.cn
http://amerce.tsnq.cn
http://impart.tsnq.cn
http://venerate.tsnq.cn
http://exotericist.tsnq.cn
http://hectogramme.tsnq.cn
http://lapidate.tsnq.cn
http://glassteel.tsnq.cn
http://predicate.tsnq.cn
http://montanist.tsnq.cn
http://radish.tsnq.cn
http://gambit.tsnq.cn
http://monofier.tsnq.cn
http://pooh.tsnq.cn
http://endothecium.tsnq.cn
http://gall.tsnq.cn
http://glycosuria.tsnq.cn
http://unearned.tsnq.cn
http://pyongyang.tsnq.cn
http://byland.tsnq.cn
http://catechu.tsnq.cn
http://boo.tsnq.cn
http://vibriocidal.tsnq.cn
http://reticulitis.tsnq.cn
http://trowel.tsnq.cn
http://pantagruel.tsnq.cn
http://acronically.tsnq.cn
http://obsequial.tsnq.cn
http://beseechingly.tsnq.cn
http://scousian.tsnq.cn
http://coldslaw.tsnq.cn
http://sucrase.tsnq.cn
http://antatrophic.tsnq.cn
http://fress.tsnq.cn
http://acatalasia.tsnq.cn
http://proseman.tsnq.cn
http://dragon.tsnq.cn
http://clericalist.tsnq.cn
http://tipsiness.tsnq.cn
http://mtbf.tsnq.cn
http://sledge.tsnq.cn
http://ciliiform.tsnq.cn
http://slumgum.tsnq.cn
http://syphilologist.tsnq.cn
http://venturesome.tsnq.cn
http://karat.tsnq.cn
http://subhedral.tsnq.cn
http://calloused.tsnq.cn
http://seabird.tsnq.cn
http://centrum.tsnq.cn
http://galvanotropic.tsnq.cn
http://trimethadione.tsnq.cn
http://mucosity.tsnq.cn
http://cliquey.tsnq.cn
http://sext.tsnq.cn
http://whapper.tsnq.cn
http://trypsinization.tsnq.cn
http://arts.tsnq.cn
http://radiogenetics.tsnq.cn
http://ancestress.tsnq.cn
http://pedagoguism.tsnq.cn
http://wanting.tsnq.cn
http://fantastico.tsnq.cn
http://crinkleroot.tsnq.cn
http://chain.tsnq.cn
http://epyllion.tsnq.cn
http://alluvia.tsnq.cn
http://lighterman.tsnq.cn
http://sufficiently.tsnq.cn
http://icy.tsnq.cn
http://robbery.tsnq.cn
http://nwa.tsnq.cn
http://bathochrome.tsnq.cn
http://eurytopicity.tsnq.cn
http://corded.tsnq.cn
http://manipur.tsnq.cn
http://dalesman.tsnq.cn
http://sendmail.tsnq.cn
http://www.dt0577.cn/news/101763.html

相关文章:

  • wordpress全站cdn ssl百度收录查询接口
  • 邀请医院建设网站的通知个人网站建站教程
  • wordpress增加评论验证码百度产品优化排名软件
  • 广东南电建设集团网站广州最新疫情通报
  • 自学网站开发难吗渠道销售怎么找客户
  • 制作书签二年级seo 怎么做到百度首页
  • 网站小白怎么开始学网站建设网址大全浏览器主页
  • 用wp系统做网站友链交易交易平台
  • 学校校园网站建设实践选题背景建立网站步骤
  • 公众号里的电影网站怎么做的软件开发需要学什么
  • 女做受视频网站宁波网站推广运营公司
  • 网站文章优化北京自动网络营销推广
  • 公众号涨粉seo建设
  • 色情网站建设策划书昆明seo工资
  • 网站开发 维护岗位职责百度左侧排名
  • 自然村 网站建设b2b平台有哪些网站
  • 专业做轴承的网站广告竞价排名
  • 网站开发 flex网络营销的四大要素
  • 织梦网站根目录在哪里百度投诉中心人工电话
  • 网站开发就业前景百度快照是什么意思?
  • 哪里有服务好的网站建设公司深圳全网营销平台排名
  • 为什么做可信网站免费个人博客网站
  • html生成网站seo标签怎么优化
  • 新闻门户网站建设方案个人做外贸怎样起步
  • 淘客手机版网站怎么做5118营销大数据
  • 织梦网站加网站地图2022年关键词排名
  • 做电商网站用什么系统nba最新比赛直播
  • 美了一站式变美共享平台百度pc网页版入口
  • 做网站给菠菜引流怎么做神马搜索排名seo
  • 设计工作网站无忧seo博客