Medium
似懂非懂,
class Solution {
public List<List<Integer>> getFactors(int n) {
List<List<Integer>> res = new ArrayList<>();
List<Integer> list = new ArrayList<>();
dfsHelper(2, 1, n, res, list);
return res;
}
private void dfsHelper(int start, int product, int n, List<List<Integer>> res, List<Integer> curt){
if (start > n || product > n){
return;
}
if (product == n){
List<Integer> factors = new ArrayList<Integer>(curt);
res.add(factors);
return;
}
for (int i = start; i < n; i++){
if (i*product > n){
break;
}
if (n % i == 0){
curt.add(i);
dfsHelper(i, i*product, n, res, curt);
curt.remove(curt.size() - 1);
}
}
}
}