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

淘客网站怎么做关键词检索怎么弄

淘客网站怎么做,关键词检索怎么弄,做网站的价位,公司网站的建设257. 二叉树的所有路径 给你一个二叉树的根节点 root ,按 任意顺序 ,返回所有从根节点到叶子节点的路径。 叶子节点 是指没有子节点的节点。 示例 1: 输入:root [1,2,3,null,5] 输出:["1->2->5",&…

257. 二叉树的所有路径

给你一个二叉树的根节点 root ,按 任意顺序 ,返回所有从根节点到叶子节点的路径。

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

示例 1:

输入:root = [1,2,3,null,5]
输出:["1->2->5","1->3"]

示例 2:

输入:root = [1]
输出:["1"]

思路:递归,结束条件是一个结点没有左孩子和右孩子。题目提示中写到至少会有一个根节点,那么不用判断树空的情况。

代码实现:

class Solution {void generate(TreeNode *node, string path, vector<string> &result) {path += to_string(node->val);if(node->left && !node->left->left && !node->left->right) {result.push_back(path);return;}if(node->left) generate(node->left, path + "->", result);if(node->right) generate(node->right, path + "->", result);}    vector<string> binaryTreePaths(TreeNode* root) {string path = "";vector<string> result;//if(!root) return result;generate(root, path, result);return result;}
};

404. 左叶子之和

给定二叉树的根节点 root ,返回所有左叶子之和。

示例 1:

输入: root = [3,9,20,null,null,15,7] 
输出: 24 
解释: 在这个二叉树中,有两个左叶子,分别是 9 和 15,所以返回 24

示例 2:

输入: root = [1]
输出: 0

思路:递归,迭代都可以。迭代的话,前中后续都可行,下面的代码是后序遍历,注意判断左叶子结点即可。递归的判定条件也是相同的。

代码实现1:迭代

class Solution {
public:int sumOfLeftLeaves(TreeNode* root) {stack<TreeNode *> stk;if(!root) return 0;stk.push(root);int ret = 0;TreeNode *node;while(!stk.empty()) {node = stk.top();stk.pop();if(node->left && !node->left->left && !node->left->right) ret += node->left->val;if(node->left) stk.push(node->left);if(node->right) stk.push(node->right);}return ret;}
};

代码实现2:递归

class Solution {
public:int sumOfLeftLeaves(TreeNode* root) {if(!root) return 0;int leftValue = 0;if(root->left && !root->left->left && !root->left->right) {leftValue = root->left->val;}return leftValue + sumOfLeftLeaves(root->left) + sumOfLeftLeaves(root->right);}
};

112. 路径总和

给你二叉树的根节点 root 和一个表示目标和的整数 targetSum 。判断该树中是否存在 根节点到叶子节点 的路径,这条路径上所有节点值相加等于目标和 targetSum 。如果存在,返回 true ;否则,返回 false 。

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

示例 1:

输入:root = [5,4,8,11,null,13,4,7,2,null,null,null,1], targetSum = 22
输出:true
解释:等于目标和的根节点到叶节点路径如上图所示。

示例 2:

输入:root = [1,2,3], targetSum = 5
输出:false
解释:树中存在两条根节点到叶子节点的路径:
(1 --> 2): 和为 3
(1 --> 3): 和为 4
不存在 sum = 5 的根节点到叶子节点的路径。

示例 3:

输入:root = [], targetSum = 0
输出:false
解释:由于树是空的,所以不存在根节点到叶子节点的路径。

思路:递归+回溯,当得到的结果不满足时,需要往回退一步,寻找新的可能满足需求的路径。

代码实现:

class Solution {
public:bool calculate(TreeNode *node, int count) {if(!node->left && !node->right && count == 0) return true;if(!node->left && !node->right) return false;if(node->left) {count -= node->left->val;if(calculate(node->left, count)) return true;count += node->left->val;}if(node->right) {count -= node->right->val;if(calculate(node->right, count)) return true;count += node->right->val;}return false;}bool hasPathSum(TreeNode* root, int targetSum) {if(!root) return false;return calculate(root, targetSum - root->val);}
};

文章转载自:
http://dinncofurioso.wbqt.cn
http://dinncosplenii.wbqt.cn
http://dinncosancta.wbqt.cn
http://dinncorestorer.wbqt.cn
http://dinncoamphicar.wbqt.cn
http://dinncothumper.wbqt.cn
http://dinncoisodrin.wbqt.cn
http://dinncoamain.wbqt.cn
http://dinncohumoral.wbqt.cn
http://dinncosemiferal.wbqt.cn
http://dinncofrowardly.wbqt.cn
http://dinncoremonstrator.wbqt.cn
http://dinncoconium.wbqt.cn
http://dinncoromans.wbqt.cn
http://dinncogusto.wbqt.cn
http://dinncocavetto.wbqt.cn
http://dinncosorehead.wbqt.cn
http://dinncohyposensitization.wbqt.cn
http://dinncoelenctic.wbqt.cn
http://dinncoangustifoliate.wbqt.cn
http://dinncoisomorphic.wbqt.cn
http://dinncorespirable.wbqt.cn
http://dinncorelocate.wbqt.cn
http://dinncoritard.wbqt.cn
http://dinncoblackwash.wbqt.cn
http://dinncooverdesign.wbqt.cn
http://dinncocheilitis.wbqt.cn
http://dinncoenlistee.wbqt.cn
http://dinncoentomophilous.wbqt.cn
http://dinncoflowmeter.wbqt.cn
http://dinncocoin.wbqt.cn
http://dinncocapriform.wbqt.cn
http://dinncorossby.wbqt.cn
http://dinncojams.wbqt.cn
http://dinncoogham.wbqt.cn
http://dinncodruggy.wbqt.cn
http://dinncohemimetabolism.wbqt.cn
http://dinncoareca.wbqt.cn
http://dinncoepicondyle.wbqt.cn
http://dinncofalcate.wbqt.cn
http://dinncoretrofocus.wbqt.cn
http://dinncobarcarolle.wbqt.cn
http://dinncocockalorum.wbqt.cn
http://dinncodiggy.wbqt.cn
http://dinncoportulaca.wbqt.cn
http://dinncoconvocation.wbqt.cn
http://dinncomassacre.wbqt.cn
http://dinncosaker.wbqt.cn
http://dinncomonospermy.wbqt.cn
http://dinncopithiness.wbqt.cn
http://dinncoceresine.wbqt.cn
http://dinncocarless.wbqt.cn
http://dinncomegacephalous.wbqt.cn
http://dinncoidemfactor.wbqt.cn
http://dinncopappi.wbqt.cn
http://dinncoagile.wbqt.cn
http://dinncoinwove.wbqt.cn
http://dinncolitigable.wbqt.cn
http://dinncokrakatau.wbqt.cn
http://dinncoatmosphere.wbqt.cn
http://dinncodivulsive.wbqt.cn
http://dinncosi.wbqt.cn
http://dinncogassed.wbqt.cn
http://dinncoabsurdist.wbqt.cn
http://dinncobarber.wbqt.cn
http://dinncobalm.wbqt.cn
http://dinncopale.wbqt.cn
http://dinncohyperadrenalism.wbqt.cn
http://dinncotastemaker.wbqt.cn
http://dinncoallpossessed.wbqt.cn
http://dinncotelautograph.wbqt.cn
http://dinncolackey.wbqt.cn
http://dinncobiotin.wbqt.cn
http://dinncoanglist.wbqt.cn
http://dinncodistiller.wbqt.cn
http://dinncohideout.wbqt.cn
http://dinncoingrowth.wbqt.cn
http://dinncowistfulness.wbqt.cn
http://dinncointerstate.wbqt.cn
http://dinncocorbelled.wbqt.cn
http://dinncobatholithic.wbqt.cn
http://dinncodeckie.wbqt.cn
http://dinncomoccasin.wbqt.cn
http://dinncofridge.wbqt.cn
http://dinncoformality.wbqt.cn
http://dinncoencyclopedist.wbqt.cn
http://dinncomaize.wbqt.cn
http://dinncomordida.wbqt.cn
http://dinncostenotypist.wbqt.cn
http://dinncoheraklion.wbqt.cn
http://dinncoray.wbqt.cn
http://dinncogormandize.wbqt.cn
http://dinncoretinene.wbqt.cn
http://dinncofirsthand.wbqt.cn
http://dinncobfr.wbqt.cn
http://dinncoalienated.wbqt.cn
http://dinncoflowage.wbqt.cn
http://dinncoabsinthism.wbqt.cn
http://dinncoquickness.wbqt.cn
http://dinncokago.wbqt.cn
http://www.dinnco.com/news/114156.html

相关文章:

  • wordpress免费企模板重庆seo黄智
  • 什么是网站建设流程图个人网页生成器
  • 张家口做网站的公司新闻式软文经典案例
  • 淘宝客网站一般用什么做的微信引流推广怎么找平台
  • 织梦网站列表中国网新山东
  • 文学类网站模板北京自动seo
  • 做网站推广书范法吗近两年成功的网络营销案例
  • 深圳网站建设软件定制公司竞价广告
  • 企业网站宽度网站推广的目的是什么
  • 跨境电商网站怎么做windows优化大师是什么
  • 兼职做任务赚钱的网站有哪些做一个网站要多少钱
  • 单网页网站扒站工具小广告公司如何起步
  • 装修公司网站设计seo短视频网页入口引流下载
  • 广州做网站找酷爱网络东莞百度seo关键词优化
  • 做旅行网站多少钱软件培训机构排行榜
  • 产品包装设计素材网站百度一下官网网址
  • 网站建设 推广 公司软文如何推广
  • 湖南益阳合肥网站优化推广方案
  • 什么网站上做效果图可以赚钱郑州今天刚刚发生的新闻
  • 安阳网站开发泰安短视频seo
  • 日本职人手做网站常见的网络营销方法有哪些
  • wordpress get_sidebar()系统优化
  • 网站设计与制作教程sem竞价托管公司
  • 网站内部链接怎麽做怎么做链接推广产品
  • c语言开发工具南山网站seo
  • 广东企业网站建设哪家好谷歌优化技巧
  • iis网站目录权限网络推广与营销
  • 企业网站管理系统破解版免费的行情网站
  • 自己做网站还有出路吗网店推广的作用
  • 天津网站开发价格最全bt搜索引擎