leetcode编辑
This commit is contained in:
42
39.combination-sum.java
Normal file
42
39.combination-sum.java
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* @lc app=leetcode id=39 lang=java
|
||||
*
|
||||
* [39] Combination Sum
|
||||
*/
|
||||
|
||||
// @lc code=start
|
||||
class Solution {
|
||||
public List<List<Integer>> combinationSum(int[] candidates, int target) {
|
||||
int[] copyArr = copy(candidates);
|
||||
Arrays.sort(copyArr);
|
||||
List<List<Integer>> combList = new ArrayList<List<Integer>>();
|
||||
|
||||
}
|
||||
|
||||
private void dfsCombinations(int[] arr, int i, int cur, int target, List<Integer> curList, List<List<Integer>> combList) {
|
||||
if(cur > target) {
|
||||
return;
|
||||
} else if (cur == target) {
|
||||
combList.add(copy(curList));
|
||||
return;
|
||||
}
|
||||
//
|
||||
}
|
||||
|
||||
private List<Integer> copy(List<Integer> comb) {
|
||||
return new ArrayList<Integer>(comb);
|
||||
}
|
||||
|
||||
private int[] copy(int[] arr) {
|
||||
if(arr == null) {
|
||||
return null;
|
||||
}
|
||||
int[] r = new int[arr.length];
|
||||
for(int i = 0; i < arr.length; i++) {
|
||||
r[i] = arr[i];
|
||||
}
|
||||
return r;
|
||||
}
|
||||
}
|
||||
// @lc code=end
|
||||
|
||||
Reference in New Issue
Block a user