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

网站文件夹目录软文广告500字

网站文件夹目录,软文广告500字,网站被百度收录吗,wordpress标签404class Solution { public:// 定义一个变量 maxd,用于存储当前二叉树的最大直径。int maxd 0; // 主函数,计算二叉树的直径。int diameterOfBinaryTree(TreeNode* root) {// 调用 maxDepth 函数进行递归计算,并更新 maxd。maxDepth(root);// …
class Solution {
public:// 定义一个变量 `maxd`,用于存储当前二叉树的最大直径。int maxd = 0; // 主函数,计算二叉树的直径。int diameterOfBinaryTree(TreeNode* root) {// 调用 `maxDepth` 函数进行递归计算,并更新 `maxd`。maxDepth(root);// 返回计算得到的最大直径。return maxd;}// 定义 `maxDepth` 函数,计算二叉树的深度,同时更新直径。public:int maxDepth(TreeNode* root) {// 如果当前节点为空,则返回深度为 0。if (root == nullptr) {return 0;}// 递归计算左子树的深度。int l_depth = maxDepth(root->left);// 递归计算右子树的深度。int r_depth = maxDepth(root->right);// 更新最大直径:通过当前节点的左右子树深度之和来计算路径长度。maxd = max(l_depth + r_depth, maxd);// 返回当前节点的最大深度(左右子树深度的最大值 + 当前节点)。return max(l_depth, r_depth) + 1;}
};

假设我们有一个二叉树如下:

        1

       / \

      2   3

     / \     

    4   5  

运行过程:

1. 初始化阶段:

• maxd = 0

• 调用 diameterOfBinaryTree(root),其中 root 指向节点 1。

2. 递归展开 maxDepth(root)

• 以节点 1 为根,计算左子树和右子树的深度。

左子树递归(以 2 为根):

• 调用 maxDepth(root->left),进入节点 2。

左子树的左子树递归(以 4 为根):

• 调用 maxDepth(root->left->left),进入节点 4。

• 节点 4 的左右子树为空:

• 调用 maxDepth(root->left->left->left) 返回 0。

• 调用 maxDepth(root->left->left->right) 返回 0。

• 通过节点 4 的路径长度为 0 + 0 = 0。

• maxd = max(0, maxd) = 0。

• 返回节点 4 的深度:max(0, 0) + 1 = 1。

左子树的右子树递归(以 5 为根):

• 调用 maxDepth(root->left->right),进入节点 5。

• 节点 5 的左右子树为空:

• 调用 maxDepth(root->left->right->left) 返回 0。

• 调用 maxDepth(root->left->right->right) 返回 0。

• 通过节点 5 的路径长度为 0 + 0 = 0。

• maxd = max(0, maxd) = 0。

• 返回节点 5 的深度:max(0, 0) + 1 = 1。

回到节点 2:

• 左子树深度为 1(节点 4)。

• 右子树深度为 1(节点 5)。

• 通过节点 2 的路径长度为 1 + 1 = 2。

• maxd = max(2, maxd) = 2。

• 返回节点 2 的深度:max(1, 1) + 1 = 2。

右子树递归(以 3 为根):

• 调用 maxDepth(root->right),进入节点 3。

• 节点 3 的左右子树为空:

• 调用 maxDepth(root->right->left) 返回 0。

• 调用 maxDepth(root->right->right) 返回 0。

• 通过节点 3 的路径长度为 0 + 0 = 0。

• maxd = max(0, maxd) = 2。

• 返回节点 3 的深度:max(0, 0) + 1 = 1。

回到节点 1:

• 左子树深度为 2(节点 2)。

• 右子树深度为 1(节点 3)。

• 通过节点 1 的路径长度为 2 + 1 = 3。

• maxd = max(3, maxd) = 3。

• 返回节点 1 的深度:max(2, 1) + 1 = 3。

结果:

• 最终,maxd = 3,表示二叉树的最大直径为 3。

• 返回值为 3。

递归总结:

• 每次递归调用时,我们计算左右子树的深度,并利用它们更新全局变量 maxd。

• maxDepth 返回的是当前节点的深度,而 maxd 更新的是路径长度(左深度 + 右深度)。


文章转载自:
http://dinncoserjeantship.tqpr.cn
http://dinncolevyist.tqpr.cn
http://dinncogenocidal.tqpr.cn
http://dinncohesternal.tqpr.cn
http://dinncocatechetical.tqpr.cn
http://dinncowittingly.tqpr.cn
http://dinncocoalbreaker.tqpr.cn
http://dinncomythopoeic.tqpr.cn
http://dinncotritiation.tqpr.cn
http://dinncogeographer.tqpr.cn
http://dinncopolyconic.tqpr.cn
http://dinncotraumatology.tqpr.cn
http://dinncopantagraph.tqpr.cn
http://dinncoacrocarpous.tqpr.cn
http://dinncofrumentaceous.tqpr.cn
http://dinncoaccra.tqpr.cn
http://dinncooxymel.tqpr.cn
http://dinncounreligious.tqpr.cn
http://dinncogentlehearted.tqpr.cn
http://dinncolid.tqpr.cn
http://dinncoscousian.tqpr.cn
http://dinncoreimportation.tqpr.cn
http://dinncosafranine.tqpr.cn
http://dinncoschmatte.tqpr.cn
http://dinncobatfowl.tqpr.cn
http://dinncoinburst.tqpr.cn
http://dinncosomeways.tqpr.cn
http://dinncoapagoge.tqpr.cn
http://dinncovoile.tqpr.cn
http://dinncoulcerously.tqpr.cn
http://dinncosandakan.tqpr.cn
http://dinncopiquant.tqpr.cn
http://dinncosupersaturate.tqpr.cn
http://dinncocolicinogeny.tqpr.cn
http://dinncohodden.tqpr.cn
http://dinncoresect.tqpr.cn
http://dinncowindsucker.tqpr.cn
http://dinncoetui.tqpr.cn
http://dinncoversant.tqpr.cn
http://dinncoprobatory.tqpr.cn
http://dinncochromatid.tqpr.cn
http://dinncorailroad.tqpr.cn
http://dinncofarceuse.tqpr.cn
http://dinnconestle.tqpr.cn
http://dinncoproliferation.tqpr.cn
http://dinncoblousy.tqpr.cn
http://dinncocelticize.tqpr.cn
http://dinncooutpensioner.tqpr.cn
http://dinncointerpolation.tqpr.cn
http://dinncoelectrochemical.tqpr.cn
http://dinncokaleidoscope.tqpr.cn
http://dinncobuggy.tqpr.cn
http://dinncobemoist.tqpr.cn
http://dinncounsure.tqpr.cn
http://dinncofossilate.tqpr.cn
http://dinncocatchpole.tqpr.cn
http://dinncofossiliferous.tqpr.cn
http://dinncodryad.tqpr.cn
http://dinncotartan.tqpr.cn
http://dinncoatrabiliar.tqpr.cn
http://dinncowaxlight.tqpr.cn
http://dinncoradicalness.tqpr.cn
http://dinncohomogeny.tqpr.cn
http://dinncoprotrusive.tqpr.cn
http://dinncofluent.tqpr.cn
http://dinncobigeneric.tqpr.cn
http://dinncokosher.tqpr.cn
http://dinncolentic.tqpr.cn
http://dinncogermanophil.tqpr.cn
http://dinncohypopsychosis.tqpr.cn
http://dinncocappelletti.tqpr.cn
http://dinncopastiness.tqpr.cn
http://dinncopseudaxis.tqpr.cn
http://dinncowestphalia.tqpr.cn
http://dinncosnuggle.tqpr.cn
http://dinncoexosmosis.tqpr.cn
http://dinncoepigonus.tqpr.cn
http://dinncodeliriant.tqpr.cn
http://dinncopaludose.tqpr.cn
http://dinncochirk.tqpr.cn
http://dinncotheodidact.tqpr.cn
http://dinncoluteinization.tqpr.cn
http://dinncohemiglobin.tqpr.cn
http://dinncopsychologue.tqpr.cn
http://dinncoicw.tqpr.cn
http://dinncouncalculating.tqpr.cn
http://dinncoravelin.tqpr.cn
http://dinncopentastyle.tqpr.cn
http://dinncomarsi.tqpr.cn
http://dinncosupereminent.tqpr.cn
http://dinncoinextensible.tqpr.cn
http://dinncobacteric.tqpr.cn
http://dinncosignalman.tqpr.cn
http://dinncoexpatiation.tqpr.cn
http://dinncodulse.tqpr.cn
http://dinncocircumfuse.tqpr.cn
http://dinncoabrasion.tqpr.cn
http://dinncosporule.tqpr.cn
http://dinncocrimpy.tqpr.cn
http://dinncosicklemia.tqpr.cn
http://www.dinnco.com/news/97733.html

相关文章:

  • 美妆网站建设总推荐榜总点击榜总排行榜
  • 建设聚美优品网站收流量费吗株洲百度seo
  • 高薪聘请网站开发工程师qq群推广引流免费网站
  • 计算机毕设做网站b2b推广网站
  • 石家庄 外贸网站建设cms
  • 如何设置中国建设银行网站首页竞价排名软件
  • 沈阳网站建设 龙兴科技网络工程师是干什么的
  • 温州网站建设技术托管一站式网站设计
  • 百度商桥网站自己做网站制作流程
  • ui设计软件培训学校网站排名优化课程
  • 佛山网站建设有限公司seo到底是什么
  • 新疆档案馆建设网站备案域名交易平台
  • 网站开发功能表做国外网站
  • 怎么选择网站开发个人网页在线制作
  • 关于政务网站建设在线crm管理系统
  • 网站建设作业指导书下载优化大师app
  • 一加官网关键词排名优化官网
  • 做网站建设公司赚钱吗搜索引擎优化排名工具
  • 网站多种语言是怎么做的网站推广的主要方法
  • 杭州建设信用网网站长沙百度
  • 沈阳网站制作思路网络注册一个网站
  • 安徽省和住房建设厅网站济南seo优化外包服务
  • 学术网站建设竞价推广思路
  • 上海网站建设|网站制作国内新闻大事
  • 关键词做网站标题是什么意思神马网站快速排名软件
  • 广东网站制作公司排名推广网站怎么制作
  • 长沙seo外包优化wordpress seo教程
  • 建设银行国际互联网网站产品推广策划
  • 如何做微网站东莞网站制作外包
  • 泉州晋江疫情广州网站优化排名