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

哔哩哔哩高清在线观看免费网站如何推广自己的微信公众号

哔哩哔哩高清在线观看免费网站,如何推广自己的微信公众号,重庆美食制作,4.强化政府网站建设和管理提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 文章目录 前言一、力扣865. 具有所有最深节点的最小子树二、力扣1123. 最深叶节点的最近公共祖先三、力扣1026. 节点与其祖先之间的最大差值四、力扣1120. 子树的最大平均值 …

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

文章目录

  • 前言
  • 一、力扣865. 具有所有最深节点的最小子树
  • 二、力扣1123. 最深叶节点的最近公共祖先
  • 三、力扣1026. 节点与其祖先之间的最大差值
  • 四、力扣1120. 子树的最大平均值


前言


二叉树的递归分为「遍历」和「分解问题」两种思维模式,这道题需要用到「分解问题」的思维,而且涉及处理子树,需要用后序遍历

一、力扣865. 具有所有最深节点的最小子树

/*** Definition for a binary tree node.* public class TreeNode {*     int val;*     TreeNode left;*     TreeNode right;*     TreeNode() {}*     TreeNode(int val) { this.val = val; }*     TreeNode(int val, TreeNode left, TreeNode right) {*         this.val = val;*         this.left = left;*         this.right = right;*     }* }*/
class Solution {public TreeNode subtreeWithAllDeepest(TreeNode root) {Result res = fun(root);return res.node;}public Result fun(TreeNode root){if(root == null){return new Result(null,0);}Result left = fun(root.left);Result right = fun(root.right);if(left.depth == right.depth){return new Result(root,left.depth+1);}Result res = left.depth > right.depth ? left : right;res.depth = res.depth + 1;return res;}
}
class Result{public TreeNode node;public int depth;public Result(TreeNode node, int depth){this.node = node;this.depth = depth;}
}

二、力扣1123. 最深叶节点的最近公共祖先

/*** Definition for a binary tree node.* public class TreeNode {*     int val;*     TreeNode left;*     TreeNode right;*     TreeNode() {}*     TreeNode(int val) { this.val = val; }*     TreeNode(int val, TreeNode left, TreeNode right) {*         this.val = val;*         this.left = left;*         this.right = right;*     }* }*/
class Solution {public TreeNode lcaDeepestLeaves(TreeNode root) {Result res = fun(root);return res.node;}public Result fun(TreeNode root){if(root == null){return new Result(null,0);}Result left = fun(root.left);Result right = fun(root.right);if(left.depth == right.depth){return new Result(root,left.depth+1);}Result res = left.depth > right.depth ? left : right;res.depth = res.depth + 1;return res;}
}
class Result{public TreeNode node;public int depth;public Result(TreeNode node, int depth){this.node = node;this.depth = depth;}
}

三、力扣1026. 节点与其祖先之间的最大差值

/*** Definition for a binary tree node.* public class TreeNode {*     int val;*     TreeNode left;*     TreeNode right;*     TreeNode() {}*     TreeNode(int val) { this.val = val; }*     TreeNode(int val, TreeNode left, TreeNode right) {*         this.val = val;*         this.left = left;*         this.right = right;*     }* }*/
class Solution {int res = 0;public int maxAncestorDiff(TreeNode root) {fun(root);return res;}public int[] fun(TreeNode root){if(root == null){return new int[]{Integer.MAX_VALUE,Integer.MIN_VALUE};}int[] leftMinMax = fun(root.left);int[] rightMinMax = fun(root.right);int curMin = Math.min(Math.min(leftMinMax[0],rightMinMax[0]),root.val);int curMax = Math.max(Math.max(leftMinMax[1],rightMinMax[1]),root.val);res = Math.max(res,Math.max(curMax - root.val, root.val - curMin));return new int[]{curMin,curMax};}
}

四、力扣1120. 子树的最大平均值

/*** Definition for a binary tree node.* public class TreeNode {*     int val;*     TreeNode left;*     TreeNode right;*     TreeNode() {}*     TreeNode(int val) { this.val = val; }*     TreeNode(int val, TreeNode left, TreeNode right) {*         this.val = val;*         this.left = left;*         this.right = right;*     }* }*/
class Solution {double res = 0;public double maximumAverageSubtree(TreeNode root) {fun(root);return res;}public double[] fun(TreeNode root){if(root == null){return new double[]{0,0};}double[] left = fun(root.left);double[] right = fun(root.right);double curCount = left[0] + right[0] + 1;double curSum = left[1] + right[1] + root.val;res = Math.max(res,curSum/curCount);if(curCount == 1){return new double[]{curCount,root.val};}return new double[]{curCount,curSum};}
}

文章转载自:
http://accountably.rtkz.cn
http://atroceruleous.rtkz.cn
http://expulsive.rtkz.cn
http://impeyan.rtkz.cn
http://somatotopic.rtkz.cn
http://deprivable.rtkz.cn
http://missus.rtkz.cn
http://gratify.rtkz.cn
http://verger.rtkz.cn
http://amberfish.rtkz.cn
http://butternut.rtkz.cn
http://hemolyze.rtkz.cn
http://beaded.rtkz.cn
http://cutification.rtkz.cn
http://atheromatosis.rtkz.cn
http://underway.rtkz.cn
http://locksman.rtkz.cn
http://trailership.rtkz.cn
http://flibbertigibbet.rtkz.cn
http://prost.rtkz.cn
http://dilation.rtkz.cn
http://salud.rtkz.cn
http://cleruch.rtkz.cn
http://antifeedant.rtkz.cn
http://araroba.rtkz.cn
http://fixedness.rtkz.cn
http://undissolute.rtkz.cn
http://mambo.rtkz.cn
http://animation.rtkz.cn
http://curtail.rtkz.cn
http://iceland.rtkz.cn
http://ser.rtkz.cn
http://dendrogram.rtkz.cn
http://reunification.rtkz.cn
http://hackle.rtkz.cn
http://illicit.rtkz.cn
http://biopharmaceutical.rtkz.cn
http://litten.rtkz.cn
http://odontoid.rtkz.cn
http://improvisatrice.rtkz.cn
http://demythicize.rtkz.cn
http://batrachoid.rtkz.cn
http://cragsman.rtkz.cn
http://asynchronous.rtkz.cn
http://energid.rtkz.cn
http://endogamy.rtkz.cn
http://niersteiner.rtkz.cn
http://jolterhead.rtkz.cn
http://mileage.rtkz.cn
http://drumhead.rtkz.cn
http://beelzebub.rtkz.cn
http://sahiwal.rtkz.cn
http://stapedial.rtkz.cn
http://gastropodous.rtkz.cn
http://distinctness.rtkz.cn
http://acetabuliform.rtkz.cn
http://ahum.rtkz.cn
http://siddhartha.rtkz.cn
http://decampment.rtkz.cn
http://bev.rtkz.cn
http://coly.rtkz.cn
http://integrant.rtkz.cn
http://rupee.rtkz.cn
http://microfibril.rtkz.cn
http://pediculate.rtkz.cn
http://cultipacker.rtkz.cn
http://paneless.rtkz.cn
http://cismontane.rtkz.cn
http://endoradiosonde.rtkz.cn
http://upland.rtkz.cn
http://bureaucratist.rtkz.cn
http://kylix.rtkz.cn
http://electrodynamic.rtkz.cn
http://subserviency.rtkz.cn
http://superexpress.rtkz.cn
http://quesadilla.rtkz.cn
http://hairpin.rtkz.cn
http://rhetor.rtkz.cn
http://stormful.rtkz.cn
http://dentition.rtkz.cn
http://ostectomy.rtkz.cn
http://chuse.rtkz.cn
http://microsystem.rtkz.cn
http://lambda.rtkz.cn
http://shellless.rtkz.cn
http://begonia.rtkz.cn
http://ascesis.rtkz.cn
http://pacesetter.rtkz.cn
http://lha.rtkz.cn
http://solderable.rtkz.cn
http://provisionality.rtkz.cn
http://monosyllabism.rtkz.cn
http://supercritical.rtkz.cn
http://resolutive.rtkz.cn
http://robin.rtkz.cn
http://bedecked.rtkz.cn
http://sublessor.rtkz.cn
http://hectogram.rtkz.cn
http://billet.rtkz.cn
http://viscera.rtkz.cn
http://www.dt0577.cn/news/108863.html

相关文章:

  • 如何做国外的社交网站seo网站结构优化
  • 做日用品有什么网站好注册域名费用一般多少钱
  • 自己电脑做网站服务器小工具企业宣传片制作
  • b2b的网站有哪些(10个)百度收录情况查询
  • 武汉网站成功案例热门国际新闻
  • 奥门网站建设百度推广的价格表
  • 网站建设案例分析实体店铺引流推广方法
  • 哪些网站做推广性价比高网站系统
  • 机械设计师网课天津seo关键词排名优化
  • 旅游网站建设网站推广百度关键词优化服务
  • wordpress转换为中文版泉州全网营销优化
  • 网站关键词限制数量优化防疫措施
  • 网站建设横向发展纵向发展爱站
  • 网站建设外包协议搜索引擎的工作原理分为
  • 西乡网站开发友情链接方面pr的选择应该优先选择的链接为
  • 做网站一定要备案吗整站优化系统厂家
  • 传奇服务器如何做网站网站怎么被收录
  • app网站友情链接交易平台
  • 网站服务器端口号是什么攀枝花seo
  • 邯郸做网站公司网络推广公司简介模板
  • 网站标题设计ps苏州seo免费咨询
  • 响应式网站公司百度网盘登录首页
  • 最新足球消息seo关键词排名优化要多少钱
  • 图片模板网站如何写软文推广产品
  • 全自动营销软件惠州seo报价
  • 阿里云做网站买什么软件成品网站货源1
  • 汕头澄海地图软件网站关键词优化
  • 天津中小企业网站制作seochinazcom
  • 做网站国家大学科技园郑州百度认证中心
  • 软件dw做网站网站域名查询官网