Skip to content

Commit 2154331

Browse files
committed
add factor comb
1 parent 743d3af commit 2154331

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

factor-combinations/README.md

Whitespace-only changes.

factor-combinations/Solution.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
public class Solution {
2+
List<List<Integer>> getFactors(int n, int low, int high) {
3+
List<List<Integer>> found = new ArrayList<>();
4+
5+
if(low <= n && n < high){
6+
found.add(Arrays.asList(n));
7+
}
8+
9+
for(int i = low; n / i >= low; i++){
10+
if(n % i == 0){
11+
for(List<Integer> sub : getFactors(n / i, i, n)){
12+
List<Integer> l = new ArrayList<>();
13+
l.add(i);
14+
l.addAll(sub);
15+
found.add(l);
16+
}
17+
}
18+
}
19+
20+
return found;
21+
}
22+
23+
public List<List<Integer>> getFactors(int n) {
24+
return getFactors(n, 2, n);
25+
}
26+
}

factor-combinations/index.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
layout: solution
3+
title: Factor Combinations
4+
date: 2015-08-12 23:03:42+08:00
5+
leetcode_id: 254
6+
---
7+
{% include_relative README.md %}

0 commit comments

Comments
 (0)