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

昆玉市网站建设_网站建设公司_SEO优化_seo优化

深圳网站设计制作,百度seo优化价格,聊城企业做网站推广,做计划网站代码随想录训练营二刷第十六天 | 104.二叉树的最大深度 559.n叉树的最大深度 111.二叉树的最小深度 222.完全二叉树的节点个数 一、104.二叉树的最大深度 题目链接#xff1a;https://leetcode.cn/problems/maximum-depth-of-binary-tree/ 思路#xff1a;后序遍历#xf…代码随想录训练营二刷第十六天 | 104.二叉树的最大深度 559.n叉树的最大深度 111.二叉树的最小深度 222.完全二叉树的节点个数 一、104.二叉树的最大深度 题目链接https://leetcode.cn/problems/maximum-depth-of-binary-tree/ 思路后序遍历层序遍历 class Solution {public int maxDepth(TreeNode root) {if (root null) return 0;int left maxDepth(root.left);int right maxDepth(root.right);return Math.max(left, right) 1;} }二、559.n叉树的最大深度 题目链接https://leetcode.cn/problems/maximum-depth-of-n-ary-tree/ 思路后序遍历加for class Solution {public int maxDepth(Node root) {if (root null) return 0;if (root.children null) return 1;int max Integer.MIN_VALUE;for (Node child : root.children) {max Math.max(max, maxDepth(child));}return max Integer.MIN_VALUE ? 1 : max 1;} }三、111.二叉树的最小深度 题目链接https://leetcode.cn/problems/minimum-depth-of-binary-tree/ 思路这题用层序遍历最快 public int minDepth(TreeNode root) {if (root null) return 0;return deep(root);}int deep(TreeNode root) {if (root.left null root.right null) return 1;int left Integer.MAX_VALUE, right Integer.MAX_VALUE;if (root.left ! null) {left minDepth(root.left);}if (root.right ! null) {right minDepth(root.right);}return Math.min(left, right) 1;}四、222.完全二叉树的节点个数 题目链接https://leetcode.cn/problems/count-complete-tree-nodes/ 思路从完全二叉树结构出发。 public int countNodes(TreeNode root) {if (root null) return 0;TreeNode left root.left, right root.right;int leftNum 0, rightNum 0;while (left ! null) {leftNum;left left.left;}while (right ! null) {rightNum;right right.right;}if (leftNum rightNum) {return (2 leftNum) - 1;}return countNodes(root.left) countNodes(root.right) 1;}
http://www.ihoyoo.com/news/63092.html

相关文章:

  • 高端网站定制开发设计制作wordpress中文主题购买
  • 网站优化网络htm5网站建设
  • 建设企业网站首页wordpress时间轴模板
  • 建材网站建设方案cute主题破解版WordPress
  • 做网站费用分摊入什么科目wordpress搜索栏
  • 如何在网站搜关键字做网站公司(深圳信科)
  • 网站建设主机网站页头制作
  • 北京市网上服务平台企业网站seo
  • h5手机网站开发demo网站建设公司工资设置
  • 个人网站可以干什么做棋牌网站多少钱
  • 网站建设属于哪个税目洛阳网站建设汉狮怎么样
  • 在阿里巴巴做网站怎么给网站上传附件
  • 网站制作商国家重点项目建设部网站
  • 淮安 网站建设:做自己的网站需要会编程吗
  • 广东购物网站建设哪家好asp.net网站开发流程及相关工具
  • 深圳地质建设网站各大网站的域名是什么原因
  • 常德小学报名网站网站开发技术的简历
  • 网站建设与运营第二次在线作业网站开发中如何制作登录页面
  • 吉林省网站制作公司有哪些网络营销专业就业公司
  • 网站营销推广广州化妆品网站建设公司排名
  • 昆明公司网站开发网站可行性分析
  • 自己建网站需要什么软件html5 php网站源码下载
  • 学做ps的软件的网站网站建设备案和免备案的区别
  • 营业范围中网站开发与网页设计公司建设网站能提升什么竞争力
  • 网站首页的尺寸做多大wordpress 留言 插件
  • 苏州哪家做网站wordpress 核心文件
  • 做相框的网站营销策划思路
  • dw做音乐网站刘强东自己做网站
  • 百度seo网站优化怎么做濮阳团购网站建设
  • 影视自助建站系统源码企业自建网站的优势