# BFS DFS recursive & DFS iterative

• ``````        // BFS 9ms
public List<List<Integer>> combineBFS(int n, int k) {
List<List<Integer>> result = new ArrayList<>();
if (k == 0) {
return result;
}
for (int i = 1; i <= n - k + 1; i++) {
List<Integer> list = new ArrayList<>();
}
for (int m = 1; m < k; m++) {
int size = result.size();
for (int i = 0; i < size; i++) {
List<Integer> list = result.get(i);
int maxNum = list.get(list.size() - 1);
int maxNumNextSize = n - k + list.size() + 1;
for (int j = maxNum + 1; j < maxNumNextSize; j++) {
List<Integer> newList = new ArrayList<>(list);
}
}
}
return result;
}

// DFS 12ms
public List<List<Integer>> combineDFS(int n, int k) {
List<List<Integer>> result = new ArrayList<>();
List<Integer> list = new ArrayList<>();
if (k == 0) {
return result;
}
if (n == 0) {
return result;
}
while (list.size() >= 1) {
int size = list.size();
int maxNum = list.get(size - 1);
if (size == k) {
while (maxNum < n) {
maxNum++;
list.remove(k - 1);
}
while (size > 0) {
maxNum = list.get(size - 1);
if (maxNum == n - k + size) {
list.remove(size - 1);
size = list.size();
} else {
list.remove(size - 1);
break;
}
}
} else {
}
}
return result;
}
// DFS Recursive 4ms
List<List<Integer>> res;
public List<List<Integer>> combineDFSRec(int n, int k) {
res = new ArrayList<>();
if (k == 0) {
return res;
}
if (n == 0) {
return res;
}
helper(new ArrayList<>(), n, k, 0);
return res;
}

public void helper(List<Integer> list, int n, int k, int maxNum) {
if (list.size() == k) {