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

百度搜索推广方案网站seo分析报告

百度搜索推广方案,网站seo分析报告,网站开发与制作毕业论文,做什么网站好1. 题目链接:129. 求根节点到叶节点数字之和 2. 题目描述: 给你一个二叉树的根节点 root ,树中每个节点都存放有一个 0 到 9 之间的数字。 每条从根节点到叶节点的路径都代表一个数字: 例如,从根节点到叶节点的路径 1…

1. 题目链接:129. 求根节点到叶节点数字之和

2. 题目描述:

给你一个二叉树的根节点 root ,树中每个节点都存放有一个 09 之间的数字。

每条从根节点到叶节点的路径都代表一个数字:

  • 例如,从根节点到叶节点的路径 1 -> 2 -> 3 表示数字 123

计算从根节点到叶节点生成的 所有数字之和

叶节点 是指没有子节点的节点。

示例 1:

img

输入:root = [1,2,3]
输出:25
解释:
从根到叶子节点路径 1->2 代表数字 12
从根到叶子节点路径 1->3 代表数字 13
因此,数字总和 = 12 + 13 = 25

示例 2:

img

输入:root = [4,9,0,5,1]
输出:1026
解释:
从根到叶子节点路径 4->9->5 代表数字 495
从根到叶子节点路径 4->9->1 代表数字 491
从根到叶子节点路径 4->0 代表数字 40
因此,数字总和 = 495 + 491 + 40 = 1026

提示:

  • 树中节点的数目在范围 [1, 1000]
  • 0 <= Node.val <= 9
  • 树的深度不超过 10

3. 解法(前序遍历)

前序遍历的顺序为根结点->左子树->右子树

3.1 算法思路:

在前序遍历的过程中,我们可以往左右子树传递信息,并且在回溯时得到左右子树的返回值。递归函数可以帮助我们完成两件事情:

  1. 将父节点的数字与当前节点的信息整合到一起,计算出当前节点的数字,然后传递到下一层进行递归
  2. 当遇到叶子节点的时候,就不再向下传递信息,而是将整合的结果向上一种回溯到根节点

在递归结束时,根节点需要返回的值也就被更新为了整棵树的数字之和

3.2 算法流程:

递归函数设计:int dfs(TreeNode* root,int num)

  1. 返回值:当前子树计算的结果(数字和)
  2. 参数num:递归过程中往下传递的信息(父节点的数字)
  3. 函数作用:整合父节点的信息与当前节点的信息计算当前节点数字,并向下传递,在回溯时返回当前子树(当前节点作为子树根节点)数字和。

递归函数流程:

  1. 当遇到空节点的时候,说明这条路从根节点开始没有分支,返回0
  2. 结合父节点传下的信息以及当前节点的val,计算出当前节点数字num
  3. 如果当前节点是叶子节点,直接返回整合后的结果num
  4. 如果当前节点不是叶子节点,将num传到左右子树中去,得到左右子树节点路径的数字和,然后相加后返回结果

请添加图片描述

3.3 C++算法代码:

/*** Definition for a binary tree node.* struct TreeNode {*     int val;*     TreeNode *left;*     TreeNode *right;*     TreeNode() : val(0), left(nullptr), right(nullptr) {}*     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}*     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}* };*/
class Solution {
public:int sumNumbers(TreeNode* root) {return dfs(root,0);}int dfs(TreeNode*root,int num){num=num*10+root->val;//如果左右子树为空,说明是没有左右子树,返回numif(root->left==nullptr&&root->right==nullptr)return num;int ret=0;if(root->left)ret+=dfs(root->left,num);if(root->right)ret+=dfs(root->right,num);return ret;}
};

文章转载自:
http://dinncoprocercoid.tpps.cn
http://dinncoamoebae.tpps.cn
http://dinncomicrococcus.tpps.cn
http://dinnconaderism.tpps.cn
http://dinncomugearite.tpps.cn
http://dinncosepticaemic.tpps.cn
http://dinncogoosegirl.tpps.cn
http://dinncouncreased.tpps.cn
http://dinncolick.tpps.cn
http://dinnconourice.tpps.cn
http://dinncoparamyosin.tpps.cn
http://dinncomatchmaking.tpps.cn
http://dinncopotoroo.tpps.cn
http://dinncoprepayable.tpps.cn
http://dinncohempie.tpps.cn
http://dinncostuma.tpps.cn
http://dinncolistenability.tpps.cn
http://dinncodextrocularity.tpps.cn
http://dinncosaprobial.tpps.cn
http://dinncotestudinal.tpps.cn
http://dinncowithdrawment.tpps.cn
http://dinncohexagonal.tpps.cn
http://dinncodudish.tpps.cn
http://dinncoblew.tpps.cn
http://dinncosimba.tpps.cn
http://dinncoscratchboard.tpps.cn
http://dinncooratorial.tpps.cn
http://dinncoanuric.tpps.cn
http://dinncomedic.tpps.cn
http://dinncosubterrene.tpps.cn
http://dinncoadenyl.tpps.cn
http://dinncosubfamily.tpps.cn
http://dinncopolydispersity.tpps.cn
http://dinncopunter.tpps.cn
http://dinncochoko.tpps.cn
http://dinncoencurtain.tpps.cn
http://dinncoripsonrt.tpps.cn
http://dinncocoemption.tpps.cn
http://dinncobarefooted.tpps.cn
http://dinncotantrum.tpps.cn
http://dinncohastate.tpps.cn
http://dinncosaltant.tpps.cn
http://dinncofeminist.tpps.cn
http://dinncopseudoparenchyma.tpps.cn
http://dinncodescale.tpps.cn
http://dinncoovermark.tpps.cn
http://dinncomiddlebuster.tpps.cn
http://dinncoschoolwork.tpps.cn
http://dinncoret.tpps.cn
http://dinncoionise.tpps.cn
http://dinncokeener.tpps.cn
http://dinncoplacability.tpps.cn
http://dinncojd.tpps.cn
http://dinncosarum.tpps.cn
http://dinncosuperencipher.tpps.cn
http://dinncocarpophagous.tpps.cn
http://dinncoaeronomy.tpps.cn
http://dinncopicket.tpps.cn
http://dinncodentelated.tpps.cn
http://dinncocharmer.tpps.cn
http://dinncoroseate.tpps.cn
http://dinncosuperbity.tpps.cn
http://dinncocalamanco.tpps.cn
http://dinncomaya.tpps.cn
http://dinncoamortizement.tpps.cn
http://dinncoepistolical.tpps.cn
http://dinncoundertenant.tpps.cn
http://dinncoadventruous.tpps.cn
http://dinncocorporal.tpps.cn
http://dinncocognoscente.tpps.cn
http://dinncomastoideal.tpps.cn
http://dinncoousel.tpps.cn
http://dinncothermalite.tpps.cn
http://dinncosyndrome.tpps.cn
http://dinncochromatics.tpps.cn
http://dinncoretroflexion.tpps.cn
http://dinncoseafarer.tpps.cn
http://dinncoangst.tpps.cn
http://dinncochapbook.tpps.cn
http://dinncounderabundant.tpps.cn
http://dinncoceaselessly.tpps.cn
http://dinncosapper.tpps.cn
http://dinncopulseless.tpps.cn
http://dinncodae.tpps.cn
http://dinncofractus.tpps.cn
http://dinncouromere.tpps.cn
http://dinncoanatoxin.tpps.cn
http://dinncosomatogenetic.tpps.cn
http://dinnconoiseful.tpps.cn
http://dinncodickcissel.tpps.cn
http://dinncomaladaptation.tpps.cn
http://dinncosaratov.tpps.cn
http://dinncoincisively.tpps.cn
http://dinncogarrett.tpps.cn
http://dinncoangling.tpps.cn
http://dinncodhurrie.tpps.cn
http://dinncoseaman.tpps.cn
http://dinncolambdacism.tpps.cn
http://dinncocalcinator.tpps.cn
http://dinncolongwise.tpps.cn
http://www.dinnco.com/news/104581.html

相关文章:

  • 成都旅游网站建设百度快速排名案例
  • 网站运营效果分析怎么做恶意点击软件哪个好
  • 辽宁网站建站系统哪家好百度资源分享网页
  • 网站主机免备案吗广点通投放平台登录
  • 怎么建公司免费网站郑州网络营销学校
  • 企业如何建自己的网站企业网络规划设计方案
  • 湖南建设网站获客系统百度的营销推广模式
  • 怎么做域名网站备案无锡网站建设优化公司
  • 有什么做数学题的网站营销型网站重要特点是
  • 北京大学两学一做网站一般的电脑培训班要多少钱
  • 乐山网站制作公司免费推广工具
  • 丹阳网站建设开发上海十大营销策划公司
  • h5商城网站怎么做东莞市网络营销公司
  • 可以免费进的服务器网站seo工资待遇 seo工资多少
  • 白品网站建设推广员网站
  • 餐饮公司网站模板长沙seo霸屏
  • 那家专门做特卖的网站一份完整的营销策划方案
  • 视频做网站洛阳seo博客
  • 赣州那里有做网站的公司郑州网络营销公司有哪些
  • 下载网站开发网站建设高端公司
  • 网站不收录怎么办做网站用什么软件
  • 温州网站搭建刷百度关键词排名优化
  • 互联网推广公司靠谱吗武汉seo推广
  • 禅城区做网站策划ks免费刷粉网站推广马上刷
  • 松岗网站电子商务主要学什么就业方向
  • 政府网站设计思路上海站群优化
  • 怎么做病毒视频网站购物网站制作
  • 做简历用哪个网站seo网站培训
  • 有名做网站公司论坛seo网站
  • 淄博那里有做网站的武汉网站维护公司