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

北京网站建设方案软件seoul是什么品牌

北京网站建设方案软件,seoul是什么品牌,小程序源码网免费下载,什邡网站建设DFS 递归: 1.判断是否失败终止 2.判断是否成功终止,如果成功的,记录一个成果 3.遍历各种选择,在这部分可以进行剪枝 4.在每种情况下进行DFS,并进行回退。 199. 二叉树的右视图 给定一个二叉树的 根节点 root&#x…

DFS

递归:
1.判断是否失败终止
2.判断是否成功终止,如果成功的,记录一个成果
3.遍历各种选择,在这部分可以进行剪枝
4.在每种情况下进行DFS,并进行回退。

199. 二叉树的右视图

给定一个二叉树的 根节点 root,想象自己站在它的右侧,按照从顶部到底部的顺序,返回从右侧所能看到的节点值。
示例 1:
在这里插入图片描述
输入: [1,2,3,null,5,null,4]
输出: [1,3,4]
示例 2:
输入: [1,null,3]
输出: [1,3]
示例 3:
输入: []
输出: []

class Solution {
public:vector<int> rightSideView(TreeNode* root) {unordered_map<int, int> rightmostValueAtDepth;int max_depth = -1;stack<TreeNode*> nodeStack;stack<int> depthStack;nodeStack.push(root);depthStack.push(0);while (!nodeStack.empty()) {TreeNode* node = nodeStack.top();nodeStack.pop();int depth = depthStack.top();depthStack.pop();if (node != NULL) {// 维护二叉树的最大深度max_depth = max(max_depth, depth);// 如果不存在对应深度的节点我们才插入if (rightmostValueAtDepth.find(depth) == rightmostValueAtDepth.end()) {rightmostValueAtDepth[depth] =  node -> val;}nodeStack.push(node -> left);nodeStack.push(node -> right);depthStack.push(depth + 1);depthStack.push(depth + 1);}}vector<int> rightView;for (int depth = 0; depth <= max_depth; ++depth) {rightView.push_back(rightmostValueAtDepth[depth]);}return rightView;}
};

39. 组合总和

给你一个 无重复元素 的整数数组 candidates 和一个目标整数 target ,找出 candidates 中可以使数字和为目标数 target 的 所有 不同组合 ,并以列表形式返回。你可以按 任意顺序 返回这些组合。
candidates 中的 同一个 数字可以 无限制重复被选取 。如果至少一个数字的被选数量不同,则两种组合是不同的。
对于给定的输入,保证和为 target 的不同组合数少于 150 个。
示例 1:
输入:candidates = [2,3,6,7], target = 7
输出:[[2,2,3],[7]]
解释:
2 和 3 可以形成一组候选,2 + 2 + 3 = 7 。注意 2 可以使用多次。
7 也是一个候选, 7 = 7 。
仅有这两种组合。
示例 2:
输入: candidates = [2,3,5], target = 8
输出: [[2,2,2,2],[2,3,3],[3,5]]
示例 3:
输入: candidates = [2], target = 1
输出: []

class Solution {
public:void dfs(vector<int>& candidates, int target, vector<vector<int>>& ans, vector<int>& combine, int index) {if (index >= candidates.size()) return;if (target==0) {ans.emplace_back(combine);return;}dfs(candidates, target, ans, combine, index+1);if (candidates[index]<=target){combine.push_back(candidates[index]);dfs(candidates, target-candidates[index], ans, combine, index);combine.pop_back();}}vector<vector<int>> combinationSum(vector<int>& candidates, int target) {vector<vector<int>> ans;vector<int> combine;dfs(candidates, target, ans, combine, 0);return ans;}
};
http://www.mmbaike.com/news/112043.html

相关文章:

  • 网站 运营 外包 每个月多少钱公众号开发网站公司
  • 香港公司建网站金华百度seo
  • 网站开发培训少儿外链在线生成
  • 天气预报网站怎么做seo关键词怎么填
  • 上海松江招聘网最新招聘优化关键词排名软件
  • c 网站建设可视化实现手机360优化大师官网
  • p2p 网站开发宁波企业seo服务
  • 百度收录不了网站seo智能优化软件
  • 绿蜻蜓建设管理有限公司网站游戏推广员每天做什么
  • 东莞市做网站的公司百度竞价推广专员
  • 汽车行业市场分析那个网站做的好百度识图鉴你所见
  • 做电商网站一般多少钱郑州seo线下培训
  • 优而思 网站app拉新佣金排行榜
  • 企业网站制作怎么做百度平台客服电话是多少
  • 三门峡做网站的公司工业设计公司
  • 长春市做网站哪家好黄页引流推广
  • 六安公司做网站2020做seo还有出路吗
  • 2022年免费ppt模板下载seo优化技术排名
  • 徐州企业建站程序百度seo优化技巧
  • 义乌建设局网站链交换
  • 丹阳网站建设报价网站seo主要是做什么的
  • 做业务在那几个网站上找客户端南宁网站关键词推广
  • 公司网站的建设哪家好做一个app软件大概要多少钱
  • 河南省做网站的公司朝阳区seo技术
  • 广州网站建设公司排行百度在线下载
  • 小学生编程网课前十名seo外链建设的方法有
  • 重庆营销型网站开发公司电话泉州百度seo公司
  • 手机网站建设商场什么是软文营销?
  • 什么网站可以做ppt模板品牌营销平台
  • 做网站算新媒体运营吗调研报告万能模板