Very simple Java solution


  • 0
    I
        public List<List<Integer>> subsets(int[] nums) {
            List<List<Integer>> result = new ArrayList<>();
    
            subsets(nums, 0, new ArrayList<>(), result);
    
            return result;
        }
    
        private void subsets(int[] nums, int start, List<Integer> solution, List<List<Integer>> result) {
            if (start == nums.length) {
                result.add(new ArrayList<>(solution));
                return;
            }
    
            subsets(nums, start + 1, solution, result);
            solution.add(nums[start]);
            subsets(nums, start + 1, solution, result);
            solution.remove(solution.size() - 1);
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.