当前位置:网站首页>leetcode. 39 --- combined sum
leetcode. 39 --- combined sum
2022-06-12 06:42:00 【_ End, broken chord】
Combinatorial summation

Answer key :
The code is as follows :
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; // dissatisfaction
if(target == 0){
// The scheme is legal , It was recorded that path in
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]); // use target - a[i] To calculate , Reduced to 0 Can
path.pop_back(); // recovery
}
}
}
};
边栏推荐
- Tomato learning notes dvector and other basics
- LeetCode-1445. Apples and oranges
- Torch models trained in higher versions report errors in lower versions
- SQL injection - Union query
- PHP read / write cookie
- An error occurred while downloading the remote file The errormessage
- 8. form label
- 五月集训(第28天)——动态规划
- Tomato learning notes -seq2seq
- [easyexcel] easyexcel checks whether the header matches the tool class encapsulated in easyexcel, including the field verification function. You can use validate to verify
猜你喜欢

Computer composition and design work06 - based on MIPS

SQL injection based on error reporting

Solution: unsatisfieddependencyexception: error creating bean with name 'authaspect':

5 ROS simulation modeling (4-navigation navigation simulation)

platform driver

CL210OpenStack操作的故障排除--章节实验

AI operation ch8

SQL injection - blind injection

2021 robocom world robot developer competition - undergraduate group (Preliminary)

库里扛起了勇士对凯尔特人的第四场
随机推荐
上位机开发(固件下载软件之需求分析)
Computer composition and design work06 —— 基于MIPS
May training (day 28) - Dynamic Planning
The principle of SQL injection is to build sqli labs, and SQL injection is simple and practical
The seventh day of June training - hash table
Upload file (post form submission form data)
SQL injection - Union query
LeetCode-1154. Day of the year
SQL 注入读写文件
LeetCode-2034. Stock price fluctuation
3 strings, containers, and arrays
LeetCode-1189. Maximum number of balloons
Codeforces Round #793 (Div. 2) A B C
六月集训 第一日——数组
VSCode常用插件
Delete the duplicate items in the ordered array -- force deduction question 26 (simple)
leetcode:890. 查找和替换模式【两个dict记录双射(set)】
Meituan won the first place in fewclue in the small sample learning list! Prompt learning+ self training practice
PHP 读写 COOKIE
A journey of database full SQL analysis and audit system performance optimization
