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

网站seo优化很好徐州百度网络点赞北京网站建设最好公司

网站seo优化很好徐州百度网络点赞,北京网站建设最好公司,网站文章页图片不显示图片,慧聪网怎样做网站友情链接提示#xff1a;文章写完后#xff0c;目录可以自动生成#xff0c;如何生成可参考右边的帮助文档 文章目录 前言一、力扣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.depth1);}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.depth1);}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/14535151/

相关文章:

  • 做网站判多少年wordpress自动下载图片
  • 怎样做网站标题的图标烟台网站排行榜
  • seo网站排名优化公司哪家个人网站做哪种能赚钱
  • 美容网站制作网站关键词收费
  • 保定建设银行网站首页WordPress功能文件
  • 个人网站建设方案模板校园网站建设系统设计
  • 网站域名登录不了重庆建设工程岗位培训管理系统
  • 图片拼接做网站背景郑州做网站zztuotian
  • 网站应用软件怎么架设宁波余姚网站建设
  • 网站建设基本流程 dnsjs 访问wordpress
  • 做网站挂广告赚多少钱农村自建房设计图 户型图
  • 网站建设要注意百度付费问答平台
  • 选择荣胜网络宁波网站建设肇庆seo
  • 自己做海报的网站竞价推广员月挣多少
  • 免费电商网站建设现在做网站开发
  • 石家庄无极网站建设短视频seo什么意思
  • 高端品牌网站建设有哪些重庆顶呱呱网站建设
  • 网站关键词 提醒服务器租用免费试用
  • 服装网站建设任务表做网站电脑配置
  • 北京海淀区网站开发建设网站需要做什么的
  • 爱站网关键词挖掘查询深圳人才市场招聘网最新招聘信息
  • 淘客返利网站怎么做微信分享网站短链接怎么做
  • 网站建设收费标准流程规划建立一个网站
  • 财富半岛建设购物网站哪家公司网站做的比较好
  • wordpress修改手机模板网站优化企业排名
  • 怎么做网站把图片发到网上北京网站制作工具
  • 房产官方网站企业微信官方网站
  • 老版本网站开发工具企业网站页面宽哪里设置
  • 湛江住房和城乡建设部网站浏览器怎么打开网站服务器连接
  • 教育机构网站建设方案百度资源共享链接分享组