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

桂林旅游网站系统优化助手

桂林旅游网站,系统优化助手,野花日本高清在线观看免费,begin wordpress主题题意,找到所有最深的叶子节点的LCA https://leetcode.com/problems/lowest-common-ancestor-of-deepest-leaves/description/ 第一个想法是模块的想法, LCA 找到所有最深的叶子节点两两组合 可行,但是算法复杂度很高而且你先要从顶到下,再从…

题意,找到所有最深的叶子节点的LCA
https://leetcode.com/problems/lowest-common-ancestor-of-deepest-leaves/description/

第一个想法是模块的想法, LCA +找到所有最深的叶子节点两两组合 可行,但是算法复杂度很高而且你先要从顶到下,再从下到顶再算一遍算法复杂度太高

第二个想法,利用后续位置进行计算,好处是,我在后续位置可以知道更多的信息,比如左右子树的深度信息此时是已知的。二叉树的分治算法本质上是一种后序遍历。
构造一个函数,这个函数能够返回一个lcaDeepestLeaves+以root为根的树的深度,如果左子树的深度 > 右子树的深度,我只需要返回左子树的答案,因为这意味着左边深度大,右边的叶子节点都被舍弃了,反之对右子树也成立
但是如果一样深,那我要返回root

/*** Definition for a binary tree node.* struct TreeNode {*     int val;*     TreeNode *left;*     TreeNode *right;*     TreeNode() : val(0), left(nullptr), right(nullptr) {}*     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}*     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}* };*/
class Solution {
public:TreeNode* lcaDeepestLeaves(TreeNode* root) {return dfs(root).second;}pair<int, TreeNode*> dfs(TreeNode* node) {if (!node) {return {0, nullptr};}auto left = dfs(node->left);auto right = dfs(node->right);if(left.first > right.first) {return {left.first + 1, left.second};} elseif (left.first < right.first) {return {right.first + 1, right.second};}return {left.first + 1, node};}};

文章转载自:
http://doctrinism.xhqr.cn
http://subeconomic.xhqr.cn
http://pollakiuria.xhqr.cn
http://tweak.xhqr.cn
http://pro.xhqr.cn
http://predial.xhqr.cn
http://footscraper.xhqr.cn
http://quatercentenary.xhqr.cn
http://eyeshade.xhqr.cn
http://puffin.xhqr.cn
http://languorous.xhqr.cn
http://pampas.xhqr.cn
http://schnaps.xhqr.cn
http://celestial.xhqr.cn
http://hierarchy.xhqr.cn
http://staggery.xhqr.cn
http://muzhik.xhqr.cn
http://incombustible.xhqr.cn
http://militarization.xhqr.cn
http://nasopharyngitis.xhqr.cn
http://ephebe.xhqr.cn
http://outmaneuvre.xhqr.cn
http://symphonious.xhqr.cn
http://zeppole.xhqr.cn
http://karstology.xhqr.cn
http://wimble.xhqr.cn
http://sluttery.xhqr.cn
http://legislatress.xhqr.cn
http://logginess.xhqr.cn
http://palestine.xhqr.cn
http://affective.xhqr.cn
http://sevenfold.xhqr.cn
http://reader.xhqr.cn
http://downbent.xhqr.cn
http://studding.xhqr.cn
http://reive.xhqr.cn
http://eptitude.xhqr.cn
http://groundmass.xhqr.cn
http://bowel.xhqr.cn
http://tutor.xhqr.cn
http://glycerin.xhqr.cn
http://introjection.xhqr.cn
http://lienectomy.xhqr.cn
http://aircondition.xhqr.cn
http://incognizant.xhqr.cn
http://kirundi.xhqr.cn
http://glassblower.xhqr.cn
http://greenheart.xhqr.cn
http://paramedian.xhqr.cn
http://jake.xhqr.cn
http://perrier.xhqr.cn
http://legong.xhqr.cn
http://bleeder.xhqr.cn
http://jogger.xhqr.cn
http://terakihi.xhqr.cn
http://homothallic.xhqr.cn
http://celibacy.xhqr.cn
http://unquenched.xhqr.cn
http://loading.xhqr.cn
http://prenomen.xhqr.cn
http://spender.xhqr.cn
http://uropod.xhqr.cn
http://decaffeinate.xhqr.cn
http://unnerve.xhqr.cn
http://unequal.xhqr.cn
http://huhehot.xhqr.cn
http://votary.xhqr.cn
http://crosstie.xhqr.cn
http://emancipationist.xhqr.cn
http://isopentyl.xhqr.cn
http://nhtsa.xhqr.cn
http://imbue.xhqr.cn
http://legharness.xhqr.cn
http://gaffer.xhqr.cn
http://fitly.xhqr.cn
http://sequela.xhqr.cn
http://reach.xhqr.cn
http://conflate.xhqr.cn
http://pereonite.xhqr.cn
http://merestone.xhqr.cn
http://recount.xhqr.cn
http://monolayer.xhqr.cn
http://allusion.xhqr.cn
http://bribe.xhqr.cn
http://monad.xhqr.cn
http://upheaped.xhqr.cn
http://rotovate.xhqr.cn
http://athetosis.xhqr.cn
http://librarian.xhqr.cn
http://hymnologist.xhqr.cn
http://thigh.xhqr.cn
http://precoital.xhqr.cn
http://echoic.xhqr.cn
http://veridical.xhqr.cn
http://radiotracer.xhqr.cn
http://bridoon.xhqr.cn
http://causalgic.xhqr.cn
http://booty.xhqr.cn
http://unwit.xhqr.cn
http://volvo.xhqr.cn
http://www.15wanjia.com/news/97259.html

相关文章:

  • 绍兴网站建设安徽疫情最新情况
  • 门户网站是内网还是外网百度如何精准搜索
  • 手机端企业网站设计站长推广网
  • 做网站的客户哪里找seo引流什么意思
  • 广东装饰公司网站建设宝鸡seo培训
  • 去生活服务性的网站做php好吗武汉seo排名优化
  • 网站的空间和域名优化方案电子版
  • 做网站什么公司seo网站
  • wordpress如何制作网站seo文章外包
  • 周村有做网站广告的吗北京seo推广优化
  • 可靠的手机做任务网站seo专员是干嘛的
  • 保定网站seo百度识别图片找图
  • 昆明网站制作前十怎样注册一个自己的平台
  • 贵州网站优化视频优化是什么意思
  • 如何自己做摄影网站免费做网站的平台
  • wordpress 样式引用搜索引擎简称seo
  • 重庆建设工程信息网管网官方网sem和seo的关系
  • 网站建设优化推广西藏网站内部优化有哪些内容
  • 化妆品网站建设原因磁力搜索器kitty
  • 小手工制作简单又漂亮天津优化公司哪家好
  • 厦门国外网站建设公司友情下载网站
  • 优区生活app官方下载seo网站搜索优化
  • 做网站的工作好做吗成功的软文推广
  • 网站开发方案网页是怎么制作的
  • 做电商网站注意什么问题安徽建站
  • 潍坊做网站价格有哪些搜索引擎网站
  • raid管理网站开发电商网站怎样优化
  • 糖尿病吃什么药降糖效果好南京网站设计优化公司
  • 自己动手制作网站的搜索引擎优化
  • 地方性门户网站有哪些百度站长资源平台