博客
关于我
[LeetCode] 40. Combination Sum II
阅读量:249 次
发布时间:2019-03-01

本文共 642 字,大约阅读时间需要 2 分钟。

注意和39题区别,当前层值相同则跳过

回溯法

void cb2help(vector
> &res,vector
&v,int target,unsigned int i,vector
recp){ if(target<0) return; else if(target==0) { res.push_back(recp); return; } for(unsigned int k=i;k
i&&v[k]==v[k-1]) continue; recp.push_back(v[k]); cb2help(res,v,target-v[k],k+1,recp); recp.pop_back(); if(target-v[k]<0) return; }}vector
> combinationSum2(vector
& v, int target){ sort(v.begin(),v.end()); vector
> res; vector
recp; cb2help(res,v,target,0,recp); return res;}

转载地址:http://erfx.baihongyu.com/

你可能感兴趣的文章
mysql索引
查看>>
mysql索引
查看>>
mysql索引、索引优化(这一篇包括所有)
查看>>
MySql索引为什么使用B+树
查看>>
WARNING!VisualDDK wizard was unable to find any DDK/WDK installed on your system.
查看>>
mysql索引创建和使用注意事项
查看>>
MySQL索引原理以及查询优化
查看>>
Mysql索引底层结构的分析
查看>>
MySQL索引底层:B+树详解
查看>>
Mysql索引总结
查看>>
MySQL索引背后的数据结构及算法原理
查看>>
mysql经常使用命令
查看>>
mysql给账号授权相关功能 | 表、视图等
查看>>
MySQL缓存使用率超过80%的解决方法
查看>>
Mysql缓存调优的基本知识(附Demo)
查看>>
mysql网站打开慢问题排查&数据库优化
查看>>
mysql网络部分代码
查看>>
mysql自动化同步校验_Shell: 分享MySQL数据同步+主从复制自动化脚本_20190313_七侠镇莫尛貝...
查看>>
mysql自增id超大问题查询
查看>>
MySQL自带information_schema数据库使用
查看>>