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

广西建设职业学院官网网站最新的网络营销的案例

广西建设职业学院官网网站,最新的网络营销的案例,手机app定制开发,郑州百姓网招聘文章目录39. 组合总和#xff1a;样例 1#xff1a;样例 2#xff1a;样例 3#xff1a;提示#xff1a;分析#xff1a;题解#xff1a;rustgoccpythonjava39. 组合总和#xff1a; 给你一个 无重复元素 的整数数组 candidates 和一个目标整数 target #xff0c;找… 文章目录39. 组合总和样例 1样例 2样例 3提示分析题解rustgoccpythonjava39. 组合总和 给你一个 无重复元素 的整数数组 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输出: []提示 1 candidates.length 302 candidates[i] 40candidates 的所有元素 互不相同1 target 40 分析 面对这道算法题目二当家的陷入了沉思。遍历或者递归递归比较直观深度优先回溯。题目要求所有可能的组合不能重复本来是需要想办法去重的但是题目规定参数中所有元素互不相同那我们只要选择不同下标的组合就相当于选择了不同元素的组合。 题解 rust impl Solution {pub fn combination_sum(candidates: Veci32, target: i32) - VecVeci32 {fn dfs(candidates: Veci32, target: i32, idx: usize, row: mut Veci32, ans: mut VecVeci32) {if idx candidates.len() {// 尝试到底开始回溯return;}if target 0 {// 符合条件的一个组合ans.push(row.clone());return;}if target candidates[idx] {// 选择当前下标数字row.push(candidates[idx]);dfs(candidates, target - candidates[idx], idx, row, ans);row.pop();}// 跳过当前下标数字dfs(candidates, target, idx 1, row, ans);}let mut ans Vec::new();dfs(candidates, target, 0, mut Vec::new(), mut ans);return ans;} }go func combinationSum(candidates []int, target int) [][]int {var ans [][]intvar dfs func(int, int, []int)dfs func(target int, idx int, row []int) {if idx len(candidates) {// 尝试到底开始回溯return}if target 0 {// 符合条件的一个组合ans append(ans, append([]int{}, row...))return}// 选择当前下标数字if target candidates[idx] {row append(row, candidates[idx])dfs(target-candidates[idx], idx, row)row row[:len(row)-1]}// 跳过当前下标数字dfs(target, idx1, row)}dfs(target, 0, []int{})return ans }c class Solution { private:void dfs(vectorint candidates, int target, int idx, vectorint row, vectorvectorint ans) {if (idx candidates.size()) {// 尝试到底开始回溯return;}if (target 0) {// 符合条件的一个组合ans.emplace_back(row);return;}// 选择当前下标数字if (target candidates[idx]) {row.emplace_back(candidates[idx]);dfs(candidates, target - candidates[idx], idx, row, ans);row.pop_back();}// 跳过当前下标数字dfs(candidates, target, idx 1, row, ans);} public:vectorvectorint combinationSum(vectorint candidates, int target) {vectorvectorint ans;vectorint row;dfs(candidates, target, 0, row, ans);return ans;} };c void dfs(int *candidates, int candidatesSize, int target, int idx, int *row, int rowSize, int **ans, int *returnSize,int **returnColumnSizes) {if (idx candidatesSize) {// 尝试到底开始回溯return;}if (target 0) {// 符合条件的一个组合ans[*returnSize] (int *) malloc(sizeof(int) * rowSize);memcpy(ans[*returnSize], row, sizeof(int) * rowSize);(*returnColumnSizes)[*returnSize] rowSize;(*returnSize);return;}// 选择当前下标数字if (target candidates[idx]) {row[rowSize] candidates[idx];dfs(candidates, candidatesSize, target - candidates[idx], idx, row, rowSize 1, ans, returnSize,returnColumnSizes);}// 跳过当前下标数字dfs(candidates, candidatesSize, target, idx 1, row, rowSize, ans, returnSize, returnColumnSizes); }/*** Return an array of arrays of size *returnSize.* The sizes of the arrays are returned as *returnColumnSizes array.* Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().*/ int **combinationSum(int *candidates, int candidatesSize, int target, int *returnSize, int **returnColumnSizes) {*returnSize 0;*returnColumnSizes (int *) malloc(sizeof(int) * 150);int **ans (int **) malloc(sizeof(int *) * 150);int row[target];dfs(candidates, candidatesSize, target, 0, row, 0, ans, returnSize, returnColumnSizes);return ans; }python class Solution:def combinationSum(self, candidates: List[int], target: int) - List[List[int]]:ans []def dfs(target: int, idx: int, row: List[int]):if idx len(candidates):# 尝试到底开始回溯returnif target 0:# 符合条件的一个组合ans.append(row.copy())return# 选择当前下标数字if target candidates[idx]:row.append(candidates[idx])dfs(target - candidates[idx], idx, row)row.pop()# 跳过当前下标数字dfs(target, idx 1, row)dfs(target, 0, [])return ans java class Solution {public ListListInteger combinationSum(int[] candidates, int target) {ListListInteger ans new ArrayList();this.dfs(candidates, target, 0, new LinkedList(), ans);return ans;}private void dfs(int[] candidates, int target, int idx, DequeInteger row, ListListInteger ans) {if (idx candidates.length) {// 尝试到底开始回溯return;}if (target 0) {// 符合条件的一个组合ans.add(new ArrayList(row));return;}if (target candidates[idx]) {// 选择当前下标数字row.addLast(candidates[idx]);this.dfs(candidates, target - candidates[idx], idx, row, ans);row.pollLast();}// 跳过当前下标数字this.dfs(candidates, target, idx 1, row, ans);} }非常感谢你阅读本文~ 欢迎【点赞】【收藏】【评论】~ 放弃不难但坚持一定很酷~ 希望我们大家都能每天进步一点点~ 本文由 二当家的白帽子https://le-yi.blog.csdn.net/ 博客原创~
http://www.hkea.cn/news/14418766/

相关文章:

  • 湖南众诚建设 官方网站网络营销推广服务合同
  • 自适应网站做多大尺寸的企业网站seo优化
  • 同城换物网站为什么做不起来网站框架图片
  • 贵阳有哪些可以制作网站的公司吗江苏天德建设工程有限公司网站
  • 盐城企业网站制作网站建设前期费用
  • 深圳网站制作公司专业网站网络架构方案规划设计和实施
  • 用dw制作做网站需要钱吗推广单页网站免费制作
  • 个人做网站有什么好处四川seo优化
  • aipage网站建设建行信用卡网站登录
  • 南宁网站制作公南昌网站建设好么
  • 山东省住房城乡建设厅查询网站威海网站建设怎么样
  • 攀枝花建设工程质量监督站投诉网站沈阳建设工程信息网作废了吗
  • 请详细说明网站开发流程及原则做网站需要那些技术
  • 北海市建设局网站企业宣传视频模板免费下载
  • 如皋住房和城乡建设局网站前端开发软件哪个最好
  • 酒店网站建设栏目分析wordpress主题know
  • 网站被黑是怎么回事啊开发 网站 费用
  • 开发网站找什么公司高新公司网站建设哪家好
  • 建设网站对公司起什么作用是什么怎样保证网站的安全性
  • 招聘网站开发人员网站开发设计怎么样
  • 网页设计与网站建设报告官网app软件免费下载
  • 康保网站制作网站建设论坛社区
  • 杭州 洛阳网站建设公司 网络服务python语言基本语句
  • 整人关不掉的网站怎么做wordpress安装权限管理
  • R shinny网站开发购物商城类app开发
  • 制作制作网站建设的豪华网站建设方案
  • 厦门公司做网站中信建设有限责任公司四川资阳分公司
  • 在网站上做外贸流量查询
  • 英文公司网站模板wordpress用户中心界面
  • 青岛做网站seo学校网页设计html代码