I have read other similar questions on StackOverflow but do not understand the root cause, and can't figure out a fix on my own. Could you help me understand what the issue is?
Here is my code:
List<List<Integer>> res;
public List<List<Integer>> permute(int[] nums) {
res = new ArrayList();
List<Integer> n = new ArrayList(Arrays.asList(nums));
permute(n, new ArrayList());
return res;
}
private void permute(List<Integer> nums, List<Integer> cur) {
if (nums.size() == 0) {
res.add(cur);
return;
}
for (int i = 0; i < nums.size(); ++i) {
List<Integer> temp = new ArrayList<Integer>(cur);
List<Integer> temp2 = new ArrayList<Integer>(nums);
Integer c = (Integer)nums.get(i); (line 20)
temp2.remove(i);
permute(temp2, temp);
}
}
but I get this error:
java.lang.ClassCastException: class [I cannot be cast to class java.lang.Integer ([I and java.lang.Integer are in module java.base of loader 'bootstrap')
at line 20, Solution.permute
at line 7, Solution.permute
at line 54, __DriverSolution__.__helper__
at line 84, __Driver__.main