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

著名的网站制作公司seo推广方法

著名的网站制作公司,seo推广方法,做传单免费的网站,网站内容更新教程代码随想录算法刷题训练营day16:LeetCode(104)二叉树的最大深度 、LeetCode(559)n叉树的最大深度、LeetCode(111)二叉树的最小深度、LeetCode(222)完全二叉树的节点个数 LeetCode(104)二叉树的最大深度 题目 代码 /*** Definition for a binary tree node.* publ…

代码随想录算法刷题训练营day16:LeetCode(104)二叉树的最大深度 、LeetCode(559)n叉树的最大深度、LeetCode(111)二叉树的最小深度、LeetCode(222)完全二叉树的节点个数

LeetCode(104)二叉树的最大深度
题目
在这里插入图片描述
代码

/*** 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 int maxDepth(TreeNode root) {//通过递归去做---传入的是根节点,可以求根节点的高度来代替深度//先求左右子树的高度+1即为根节点的高度----确定遍历方式为左右根//采用递归,先判断终止条件if(root==null){return 0;}//不为空,先求左子树的高度int heightLeft=maxDepth(root.left);//再求右子树的高度int heightRight=maxDepth(root.right);int heightRoot;//定义根节点的高度if(heightLeft>heightRight){heightRoot=heightLeft+1;}else{heightRoot=heightRight+1;}return heightRoot;}
}

LeetCode(559)n叉树的最大深度
题目
在这里插入图片描述
代码

// @lc code=start
/*
// Definition for a Node.
class Node {public int val;public List<Node> children;public Node() {}public Node(int _val) {val = _val;}public Node(int _val, List<Node> _children) {val = _val;children = _children;}
};
*/class Solution {public int maxDepth(Node root) {//同样用后续遍历去做if(root==null){return 0;}int maxheight=0;List<Node> childrens=root.children;//遍历集合for (Node children : childrens) {int tempHeight=maxDepth(children);if(tempHeight>maxheight){maxheight=tempHeight;//找出所有子树中节点最高的树}    }return maxheight+1;    }
}

LeetCode(111)二叉树的最小深度
题目
在这里插入图片描述

代码

// @lc code=start
/*** 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 int minDepth(TreeNode root) {if(root==null){return 0;}int rootHeight;//同样用后续遍历去做if(root.left==null){rootHeight=minDepth(root.right)+1;return rootHeight;}if(root.right==null){rootHeight=minDepth(root.left)+1;return rootHeight;}int leftHeight=minDepth(root.left);int rightHeight=minDepth(root.right);if(leftHeight<rightHeight){rootHeight=leftHeight+1;}else{rootHeight=rightHeight+1;}return rootHeight;}

LeetCode(222)完全二叉树的节点个数
题目
在这里插入图片描述
代码

// @lc code=start
/*** 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 number=0;public int countNodes(TreeNode root) {if(root==null){return 0;}int leftCountNodes=countNodes(root.left);int rightCountNodes=countNodes(root.right);int countSum=leftCountNodes+rightCountNodes+1;//常规遍历方法return countSum;}
}
http://www.tj-hxxt.cn/news/6485.html

相关文章:

  • 企业网站建设免费数据分析平台
  • wordpress gif缩略图黑帽seo联系方式
  • 自己做网站好还是凡科seo手机端排名软件
  • 招商网站建设免费今日疫情最新消息
  • 镇江门户网站手机网站快速建站
  • 创建一个网站的步骤是登封搜索引擎优化
  • 中国建筑装饰网家居频道seo网站的优化方案
  • pc网站制作公司seo站长工具是什么
  • 合肥做网站行吗seo网站搜索优化
  • 网站备案产品信息错误百度链接地址
  • 做好党史网站的建设厦门人才网招聘最新信息
  • 清河做网站报价站长之家app下载
  • 国内免费工厂网站建设郑州seo询搜点网络效果佳
  • php网站设计人员天津短视频seo
  • 代理是干什么的seo关键词排名优
  • 网页设计特效网站优化大师有必要花钱吗
  • 做动态网站需要什么书网络营销常用的工具有哪些
  • 萍乡网站建设公司白杨seo博客
  • 外贸推广网站收费吗搜索引擎优化的目的是
  • 怎么写网站文案软文世界平台
  • 做网站怎么开后台游戏推广接单平台
  • 在大网站做网页广告需要多少钱关键词搜索爱站网
  • 郑州做网站推广地址微信推广广告在哪里做
  • 社交网站模板下载网站注册流程
  • 自做刷赞网站内容营销的4个主要方式
  • 毕业设计做网站还是系统如何申请域名
  • 手机怎样使用域名访问网站厦门seo招聘
  • 做网站的服务器cpu异常seo收费标准多少
  • 计算机网络技术 网站建设线上广告接单平台
  • asp.net网站开发流程及相关工具企业文化设计