-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlc-39.java
More file actions
23 lines (23 loc) · 719 Bytes
/
lc-39.java
File metadata and controls
23 lines (23 loc) · 719 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Solution {
List<List<Integer>> res = new ArrayList();
public List<List<Integer>> combinationSum(int[] candidates, int target) {
Arrays.sort(candidates);
find(candidates, target, 0, new ArrayList());
return res;
}
private void find(int[] cs, int target, int s, List comb) {
if(target > 0) {
for(int i = s; i<cs.length; i++) {
comb.add(cs[i]);
find(cs, target-cs[i], i, comb);
comb.remove(comb.size()-1);
}
}else if(target == 0){
res.add(new ArrayList(comb));
return;
}else {
//comb.remove(comb.size()-1);
return;
}
}
}