Hi, this is Shunchi!

  • Home

  • Tags0

  • Archives267

  • Categories0

  • Curricula

  • DSA

  • LeetCode_Notes

  • Interviews

  • General

  • Resume

39. Combination Sum

Posted on 2020-06-28 | Edited on 2021-01-26

LeetCode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class Solution {
private void util(int[] arr, int target, List<List<Integer>> res, List<Integer> ls,int start){
if(target<0){
return;
}else if(target==0){
res.add(new ArrayList(ls));
return;
}else{
for(int i=start;i<arr.length;i++){
ls.add(arr[i]);
util(arr,target-arr[i],res,ls,start);
ls.remove(ls.size()-1);
start+=1;
}
}
}
public List<List<Integer>> combinationSum(int[] candidates, int target) {
List<List<Integer>> res=new ArrayList<>();
util(candidates,target,res,new ArrayList<>(),0);
return res;
}
}

<1…129130131…267>
ShunchiZhou

ShunchiZhou

267 posts
RSS
GitHub E-Mail Gitbook Linkedin
© 2024 ShunchiZhou
Powered by Hexo v5.4.0
|
0%