当前位置:网站首页>leetcode.39 --- 组合总和
leetcode.39 --- 组合总和
2022-06-12 06:39:00 【_End丶断弦】
组合总和

题解:
代码如下:
class Solution {
public:
vector<vector<int>> ans;
vector<int> path;
vector<vector<int>> combinationSum(vector<int>& candidates, int target) {
dfs(candidates,0,target);
return ans;
}
void dfs(vector<int>&a,int u,int target)
{
if(target < 0) return; //不满足
if(target == 0){
//该方案合法,记录到path中
ans.push_back(path);
return;
}
for(int i = u;i < a.size();i++)
{
if(a[i] <= target){
path.push_back(a[i]);
dfs(a,i,target - a[i]); //用target - a[i]来算,减到0就可以
path.pop_back(); //恢复
}
}
}
};
边栏推荐
- Deep and detailed analysis of PHP one sentence Trojan horse
- Bid farewell to the charged xshell, and the free function of tabby is more powerful
- Excel VBA opens a file that begins with the specified character
- LeetCode-884. Unusual words in two sentences
- SQL injection read / write file
- android studio 利用数据库实现登录注册界面功能
- Video summary with long short term memory
- Redis basic notes
- Modifying theme styles in typora
- Redis configuration (III) -- master-slave replication
猜你喜欢

Multithreading (V) -- concurrency tools (I) -- thread pool (II) -- related contents of ThreadPoolExecutor

Tips for using the potplayer video player

2021 RoboCom 世界机器人开发者大赛-本科组(初赛)

Zhang Chi's class: Notice on the time of CAQ Six Sigma test in 2022

SQL injection based on error reporting

Opencv_100问_第五章 (21-25)

Vscode Common plug - in

Deep and detailed analysis of PHP one sentence Trojan horse

Redis configuration (IV) -- cluster

Leetcode January 10 daily question 306 Additive number
随机推荐
Install MySQL tutorial
Tips for using the potplayer video player
SQL 注入读写文件
leetcode 35. Search insert location
Delete the duplicate items in the ordered array -- force deduction question 26 (simple)
Trunet: short videos generation from long videos via story preserving truncation (thesis translation)
Redis supports data structure types
AI作业ch8
六月集训 第六日——滑动窗口
How to build your own website (using the pagoda panel)
CONDA create use virtual environment
张驰咨询:流程是一剂万能良药吗?
Excel VBA opens a file that begins with the specified character
Bulk Rename Utility
Torch models trained in higher versions report errors in lower versions
Redis application (I) -- distributed lock
SQL injection based on error reporting
LeetCode-884. Unusual words in two sentences
Use ms17-010 Eternal Blue vulnerability to infiltrate win7 and establish a permanent back door
The fifth day of June training - double pointer
