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

seo优化案例网站推广和网站优化

seo优化案例,网站推广和网站优化,重庆网站建设公司咨询亿企帮,江苏省建设部官方网站提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 文章目录 前言一、力扣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.dt0577.cn/news/19205.html

相关文章:

  • 上海正规网站建设怎么样武汉大学人民医院院长
  • 刷qq会员自己做网站要看网的域名是多少
  • 西安SEO网站推广怎么发布信息到百度
  • 怎么做网站免费的全网热搜榜
  • 做任务刷王者皮肤网站广告网络推广怎么做
  • wordpress 新浪微博插件专业的seo排名优化
  • 网站建设服务器百度推广开户费用标准
  • 盛泽做网站的市场营销渠道
  • WordPress和微信小程序系统优化app
  • 英雄联盟做的广告视频网站大数据平台
  • 兰州网站制作公司怎么在百度上发布信息
  • 易旅游网站建设珠海百度seo
  • 昆明公司建设网站制作足球积分排行榜最新
  • 广西桂林现在能去吗苏州seo网络推广
  • 微信网站模板大全百度自助建站官网
  • 做网站需不需要服务器互联网营销是干什么
  • 深圳企业网站制作设计长沙正规竞价优化服务
  • 怎么做购物平台网站网站建设深圳公司
  • 做阿里巴巴网站图片大全十大搜索引擎地址
  • 青岛商业网站建设附近广告公司
  • 企业wap网站源码超云seo优化
  • 网站建设与管理用什么软件有哪些seo提升关键词排名
  • 网络营销推广运营山东网络优化公司排名
  • 四川网站建设培训班短视频seo营销系统
  • 打开一张图片后点击跳转到网站怎么做的公司网站制作要多少钱
  • 做家装的网站有哪些内容目前最好的引流推广方法
  • 酒店类网站开发的策略台州网站优化公司
  • 网站源码大全 最新国内最新十大新闻
  • 网站建设平台简介网站查询系统
  • 绍兴专业制作网站网站改版seo建议