Algorithm
题解:
使用回溯算法将每种组合都进行尝试
源码
public List<List<Integer>> combinationSum2(int[] candidates, int target) {
List<List<Integer>> lists = new ArrayList<>();
Stack<Integer> stack = new Stack<>();
Arrays.sort(candidates);// 先排个序,好进行重复的判断
helper(lists,stack,candidates,target,0);
return lists;
}
private void helper(List<List<Integer>> lists,Stack<Integer> stack,int[] candidates,int target,int start){
if (0 == target) {
lists.add(new ArrayList<>(stack));
} else if (target < 0){
return;
} else {
for (int i = start; i <candidates.length ; i++) {
// candidates 中的每个数字在每个组合中只能使用 一次 。所以直接跳过重复的
if (i>start && candidates[i] == candidates[i-1]) continue;
stack.push(candidates[i]);
helper(lists,stack,candidates,target-candidates[i],i+1);
stack.pop();// 剪枝
}
}
}
Review
英文暂时没看~
Tip
getBean的流程
清单是指beanName即需要的bean
采购人员是ObjectFactory,操作需要加上lock
第一次来确认清单,第二次来必须要等到改清单
第一次和第二次(传入一个lamda表达式)
并且放入singletonObjects中去
Share
分享一下春游的照片吧,自己体验了一把照相师的装逼快感,有想买一个的冲动