今日收获:组合总和,组合总和Ⅱ,分割回文串
代码随想录:for循环横向遍历,递归纵向遍历,回溯不断调整结果集。
1. 组合总和
思路:和216. 组合总和 III - 力扣(LeetCode)很像,不同之处在于可以重复选择当前元素,所以递归时start不用+1
方法:
class Solution {
List<Integer> path=new ArrayList<>();
List<List<Integer>> result=new ArrayList<>();
public List<List<Integer>> combinationSum(int[] candidates, int target) {
// 先进行排序
Arrays.sort(candidates);
back(candidates,target,0);
return result;