1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| public static void main(String[] args) { Solution solution = new Solution(); int[] candidates = new int[]{2, 3, 6, 7}; int target = 7; List<List<Integer>> res = solution.combinationSum(candidates, target); System.out.println("输出 => " + res); }
打印结果: 递归之前 => [2],剩余 = 5 递归之前 => [2, 2],剩余 = 3 递归之前 => [2, 2, 2],剩余 = 1 递归之前 => [2, 2, 2, 2],剩余 = -1 递归之后 => [2, 2, 2] 递归之前 => [2, 2, 2, 3],剩余 = -2 递归之后 => [2, 2, 2] 递归之前 => [2, 2, 2, 6],剩余 = -5 递归之后 => [2, 2, 2] 递归之前 => [2, 2, 2, 7],剩余 = -6 递归之后 => [2, 2, 2] 递归之后 => [2, 2] 递归之前 => [2, 2, 3],剩余 = 0 递归之后 => [2, 2] 递归之前 => [2, 2, 6],剩余 = -3 递归之后 => [2, 2] 递归之前 => [2, 2, 7],剩余 = -4 递归之后 => [2, 2] 递归之后 => [2] 递归之前 => [2, 3],剩余 = 2 递归之前 => [2, 3, 3],剩余 = -1 递归之后 => [2, 3] 递归之前 => [2, 3, 6],剩余 = -4 递归之后 => [2, 3] 递归之前 => [2, 3, 7],剩余 = -5 递归之后 => [2, 3] 递归之后 => [2] 递归之前 => [2, 6],剩余 = -1 递归之后 => [2] 递归之前 => [2, 7],剩余 = -2 递归之后 => [2] 递归之后 => [] 递归之前 => [3],剩余 = 4 递归之前 => [3, 3],剩余 = 1 递归之前 => [3, 3, 3],剩余 = -2 递归之后 => [3, 3] 递归之前 => [3, 3, 6],剩余 = -5 递归之后 => [3, 3] 递归之前 => [3, 3, 7],剩余 = -6 递归之后 => [3, 3] 递归之后 => [3] 递归之前 => [3, 6],剩余 = -2 递归之后 => [3] 递归之前 => [3, 7],剩余 = -3 递归之后 => [3] 递归之后 => [] 递归之前 => [6],剩余 = 1 递归之前 => [6, 6],剩余 = -5 递归之后 => [6] 递归之前 => [6, 7],剩余 = -6 递归之后 => [6] 递归之后 => [] 递归之前 => [7],剩余 = 0 递归之后 => [] 输出 => [[2, 2, 3], [7]]
|