package leetcode;

import java.util.List;

/**
 * https://leetcode.com/problems/increasing-subsequences/
 */
public class Problem491 {
    public List<List<Integer>> findSubsequences(int[] nums) {
        // TODO
        return null;
    }

    public static void main(String[] args) {
        Problem491 prob = new Problem491();
        System.out.println(prob.findSubsequences(new int[]{1, 1, 1})); // [[1, 1], [1, 1, 1]]
        System.out.println(prob.findSubsequences(new int[]{1, 2, 2})); // [[1, 2], [2, 2], [1, 2, 2]]
        System.out.println(prob.findSubsequences(new int[]{4, 6, 7, 7})); // [[4, 6], [4, 7], [4, 6, 7], [4, 6, 7, 7], [6, 7], [6, 7, 7], [7,7], [4,7,7]]
    }
}

@@ -33,13 +33,114 @@
 til.
+Array
 List;
+%0Aimport java.util.Arrays;%0Aimport java.util.HashSet;%0Aimport java.util.List;%0Aimport java.util.Set;
 %0A%0A/*
@@ -303,36 +303,840 @@
     
-// TODO%0A        return null;
+Arrays.sort(nums);%0A        List%3CInteger%3E list = new ArrayList%3C%3E();%0A        for (int num : nums) %7B%0A            list.add(num);%0A        %7D%0A        Set%3CList%3CInteger%3E%3E result = new HashSet%3C%3E();%0A        findSubsequences(list, result);%0A        return new ArrayList%3C%3E(result);%0A    %7D%0A%0A    private static void findSubsequences(List%3CInteger%3E nums, Set%3CList%3CInteger%3E%3E result) %7B%0A        if (nums.size() %3C= 1) %7B%0A            return;%0A        %7D%0A        result.add(nums);%0A        for (int i = 0; i %3C nums.size(); i++) %7B%0A            List%3CInteger%3E newList = new ArrayList%3C%3E();%0A            if (i - 1 %3E= 0) %7B%0A                newList.addAll(nums.subList(0, i));%0A            %7D%0A            if (i + 1 %3C= nums.size() - 1) %7B%0A                newList.addAll(nums.subList(i + 1, nums.size()));%0A            %7D%0A            findSubsequences(newList, result);%0A        %7D
 %0A   
@@ -1424,16 +1424,16 @@
  2, 2%5D%5D%0A
-
         
@@ -1578,16 +1578,96 @@
 4,7,7%5D%5D%0A
+        System.out.println(prob.findSubsequences(new int%5B%5D%7B4, 3, 2, 1%7D)); // %5B%5D%0A
     %7D%0A%7D%0A

Update problem 491