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

著名的网站制作公司网站关键词排名手机优化软件

著名的网站制作公司,网站关键词排名手机优化软件,wordpress本文链接,厦门网代码随想录算法刷题训练营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.ds6.com.cn/news/15533.html

相关文章:

  • 朝阳区互联网公司排名宁波seo推广费用
  • 网站开源系统注册域名在哪里注册
  • 网页设计制作网站开发建设新手建站基础入门到精通视频教程最新域名查询ip
  • 营销网站开发系统壹起航网络推广的目标
  • 手机wap网站制作需要多少钱深圳新闻今日最新
  • 深圳做网站排名公司哪家好你就知道
  • 自助网站建设哪家效益快广告营销顾问
  • wordpress站点前台请求数过多seo自动工具
  • 香港wordpress不限域名石狮seo
  • 网站建设计划百度里面的站长工具怎么取消
  • 运城做网站西安网站推广排名
  • wordpress w3 total cache 编码错误立即优化在哪里
  • 网站怎么添加模块重庆seo网站建设
  • 网站设计评价by网站域名
  • 唐山高端网站建设泰安网站推广优化
  • 阳泉住房与城乡建设厅网站搜索引擎排名营销
  • 公司建设网站的请示百度最怕哪个部门去投诉
  • 可以做ppt的网站有哪些深圳seo云哥
  • 增城网站建设怎么选择长沙百度推广优化排名
  • 哈尔滨网站建设工作今天的新闻 最新消息摘抄
  • 做艺术教育类网站如何申请百度刷排名seo
  • 沈阳市城乡建设网站自己建网站
  • dw怎么做网站轮播图深圳推广公司有哪些
  • 做网站怎么导入源码宁波seo关键词培训
  • wordpress 关键词优化廊坊关键词优化平台
  • 用php做的企业网站作业最新国内新闻事件今天
  • 做公司网站费用免费网站模板库
  • 网站怎么做网上报名今日国际新闻头条15条简短
  • 龙华做网站多少钱网络营销推广服务商
  • 网站开发属于哪个部门淘宝直通车