leetcode 40: Combination Sum II
2015-07-08 15:58
423 查看
class Solution { public: vector<vector<int>> combinationSum2(vector<int>& candidates, int target) { vector<vector<int> > res; vector<int> set; sort(candidates.begin(),candidates.end()); helper(candidates,0,target,set,res); return res; } void helper(vector<int>& candidates,int idx,int target,vector<int>& set,vector<vector<int> >& res){ for(int i=idx;i<candidates.size()&&candidates[i]<=target;i++) { if(i==idx||candidates[i]!=candidates[i-1])//The cases with repeat numbers are considered in the recursion, so they should not be considered in the loop { set.push_back(candidates[i]); if(candidates[i]==target) { res.push_back(set); set.pop_back(); break; } else { helper(candidates,i+1,target-candidates[i],set,res); set.pop_back(); } } } } };
相关文章推荐
- codeforces 229/D 动态规划
- 【leetcode】 Anagrams
- Redis基础命令
- JAVA微信开发:[20]如何实现主动发送微信消息
- java学习篇-----图形用户界面基础:0
- TI 问题
- 一句Python命令启动一个Web服务器
- Selenium2(webdirver)入门之环境搭建(Java版)
- JavaWeb学习笔记--Listener
- wamp下php无法保存SESSION问题总汇
- 以cmd命令行方式执行php文件时,传递参数
- Access-Control-Allow-Origin与跨域
- CentOS安装雷凌RT5370 Wireless Adapter无线网卡驱动
- yum 快速搭建lnmp环境
- Apache对象池插件common-pool学习小结
- SAP升级数据库ASE报 kernel SySAM: Licenses exist for ASE, but a license containing the configured (PE=EE
- 网页中实现复制功能
- Java编程语言中栈与堆内存区别详解
- MS-DOS命令
- 在Oracle中如何删除表中设计重复数据