I'm doing a problem on leetcode: given a list of integers, return a list of lists that contains all the possible permutation of these numbers. The class and method are the following:
class Solution {
public List<List<Integer>> permute(int[] nums) {
List<List<Integer>> permu = new ArrayList<ArrayList<Integer>>();
more code here ...
}
}
The compiler threw an error "ArrayList<ArrayList<Integer>> cannot be converted to List<List<Integer>>".
I know that the return type must be List<List<Integer>>
instead of ArrayList<ArrayList<Integer>>
, but I can't declare List<List<Integer>> permu = new List<List<Integer>>();
because list is an interface. How should I declare permu correctly, if I'm not allowed to change the return type in the permute method?
> permu = new ArrayList
– khelwood May 15 '21 at 17:06>();` or `new ArrayList<>();`
>();` work?
– deHaar May 15 '21 at 17:06>`.