leetcode week18
来源:互联网 发布:维也纳新年音乐会 知乎 编辑:程序博客网 时间:2024/05/20 09:05
Combination Sum
Given a set of candidate numbers (C) (without duplicates) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.
The same repeated number may be chosen from C unlimited number of times.
Note:
- All numbers (including target) will be positive integers.
- The solution set must not contain duplicate combinations.
For example, given candidate set [2, 3, 6, 7]
and target 7
,
A solution set is:
[ [7], [2, 2, 3]]
class Solution {public: vector<vector<int>> combinationSum(vector<int>& candidates, int target) { vector<vector<int> > res; vector<int> out; sort(candidates.begin(),candidates.end()); combinationSumDFS(candidates,out,0,target,res); return res; } void combinationSumDFS(vector<int>& candidates,vector<int> &out,int start,int target,vector<vector<int> > &res) { if(target<0) return; else if(target == 0) res.push_back(out); else { for(int i =start;i<candidates.size();i++) { out.push_back(candidates[i]); combinationSumDFS(candidates,out,i,target-candidates[i],res); out.pop_back(); } } } };
阅读全文
0 0
- Leetcode week18
- leetcode week18
- leetcode week18
- leetcode week18
- leetcode week18
- leetcode week18
- leetcode week18
- LeetCode Week18: Sicily Test
- 算法设计Week18 LeetCode Algorithms Problem #344 Integer Break
- week18- NO.128. Longest Consecutive Sequence
- leetcode
- [leetcode]
- LeetCode
- leetcode
- leetcode
- leetcode:
- leetcode:
- LeetCode
- 素数分解定理
- org.apache.hadoop.ipc.Client: Retrying connect to server: 0.0.0.0/0.0.0.0:8031
- ZOJ--1016:Parencodings
- Ubuntu16.04更换漂亮绚丽flatabulous主题
- android源码下载
- leetcode week18
- 012--swift实现通讯录(用到基础语法)
- 访问PCIe BAR空间
- 系统的环境变量path的作用是什么
- 浅谈Javaweb经典三层架构和MVC框架模式
- VS2008+CUDA6.0 出现LINK:fatal error LINK1146:没用选项"/LIBPATH"指定的参数
- iOS vim基本命令~笔记
- 深入浅出RxJava(一:基础篇)
- Java并发编程实践---第二章:线程安全性