电脑上补代码
```
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Permutation {
interface Generator<T> {
T next();
boolean hasNext();
}
static class PermutationGenerator implements Generator<List<Integer>> {
final private int[] index;
final List<List<Integer>> nums;
private boolean hasNext = true;
public PermutationGenerator(List<List<Integer>> nums) {
this.nums = nums;
index = new int[nums.size()];
}
@
Override public List<Integer> next() {
List<Integer> ret = new ArrayList<>();
if (!hasNext)
return ret;
for (int i = 0; i < index.length; i++) {
ret.add(nums.get(i).get(index[i]));
}
int resetCount = 0;
for (int i = 0; i < index.length; i++) {
if (index[i] < nums.get(i).size() - 1) {
index[i]++;
break;
} else {
index[i] = 0;
resetCount++;
}
}
if (resetCount == index.length) {
hasNext = false;
}
return ret;
}
@
Override public boolean hasNext() {
return hasNext;
}
}
public static void main(String[] args) {
List<List<Integer>> data = Arrays.asList(Arrays.asList(1, 2, 3), Arrays.asList(4, 5, 6), Arrays.asList(7, 8, 9));
Generator<List<Integer>> gen = new PermutationGenerator(data);
while (gen.hasNext()) {
System.out.println(gen.next());
}
}
}
```