254. Factor Combinations
Factor Combinations
Solution
public class Solution {
public List<List<Integer>> getFactors(int n) {
List<List<Integer>> result = new ArrayList<>();
helper(result, new ArrayList<>(), n, 2);
return result;
}
private void helper(List<List<Integer>> result, List<Integer> current, int n, int start) {
if (n <= 1) {
if (current.size()>=2) {
result.add(new ArrayList<Integer>(current));
}
return;
}
for (int i = start; i <= n; i++) {
if (n % i == 0) {
current.add(i);
helper(result, current, n / i, i);
current.remove(current.size() - 1);
}
}
}
}Last updated