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

做网站封面要怎么做企业网站建设方案策划书

做网站封面要怎么做,企业网站建设方案策划书,中国建设银行e路通网站,广州全网络营销提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 文章目录 前言一、力扣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://www.hkea.cn/news/189616/

相关文章:

  • 昆明做大的网站开发公司google网页搜索
  • 做网站运营需要什么证宁波靠谱营销型网站建设
  • 天津进口网站建设电话青岛网站建设公司
  • 游戏币网站建设win7优化大师官方网站
  • 技术专业网站建设班级优化大师网页版登录
  • 外国网站上做雅思考试台州百度推广优化
  • 男女做那种的的视频网站国内最好的搜索引擎
  • 泉州做网站优化价格成功品牌策划案例
  • 做网站去哪个平台资源优化排名网站
  • 备案的网站名称可以改吗百度青岛代理公司
  • 专做进口批发的网站关键词优化多少钱
  • 做网站有了空间在备案吗百度权重高的网站有哪些
  • 做空间的网站著名的网络营销案例
  • 做网站客户尾款老不给怎么办百度推广年费多少钱
  • 想要将网站信息插到文本链接怎么做百度关键词搜索
  • 江苏网站备案要多久seo域名综合查询
  • 大型网站建设机构津seo快速排名
  • 建设证件查询官方网站宁波做网站的公司
  • 那些网站招聘在家里做的客服网店推广策略
  • 湘西 网站 建设 公司sem代运营托管公司
  • 用css为wordpress排版西安seo外包服务
  • vs2005做网站百度推广官方网站登录入口
  • 乐从网站建设公司北京seo优化推广
  • 如何在网上接做网站的小项目市场监督管理局电话
  • 淘宝购物站优化
  • 石家庄最新疫情轨迹河南网站优化公司哪家好
  • 网站色彩搭配服务器ip域名解析
  • 哪个网站专业做安防如何注册域名网站
  • 穆棱市住房和城乡建设局网站关键词词库
  • 成都网站建设市场什么是网络营销的核心