educative.io

Mine return value was empty

Arrays.sort(nums);
List<List> subsets = new ArrayList<>();
subsets.add(new ArrayList<>());
int start = 0, end = 0;
for(int i=0; i<nums.length; i++){
start = 0;
if(i>0 && nums[i] == nums[i-1]) {
start = end + 1;
}
end = subsets.size() - 1;

        for(int j=start; j<end;j++){
            List<Integer> temp = new ArrayList<>(subsets.get(j));
            temp.add(nums[i]);
            subsets.add(temp);
        }
    }

    return subsets;

above is my code, I’m not getting it, mine looks pretty much the same as the correct answer, but return value was all empty


Type your question above this line.

Course: https://www.educative.io/collection/5668639101419520/5671464854355968
Lesson: https://www.educative.io/collection/page/5668639101419520/5671464854355968/5654100301578240

nvm, I solved it, should be <=end instead of <

Hello @Li_Zengping

I dry ran your code and the problem was as you have already mentioned. It should have been <= end instead of <.