Increasing Subsequences

491. Increasing Subsequences

Given an integer array, your task is to find all the different possible increasing subsequences of the given array, and the length of an increasing subsequence should be at least 2 .

Example:

Input: [4, 6, 7, 7]  
Output: [[4, 6], [4, 7], [4, 6, 7], [4, 6, 7, 7], [6, 7], [6, 7, 7], [7,7], [4,7,7]]  

Note:
The length of the given array will not exceed 15.
The range of integer in the given array is [-100,100].
The given array may contain duplicates, and two equal integers should also be considered as a special case of increasing sequence.

public class Solution {  
    public List<List<Integer>> findSubsequences(int[] nums) {
        Set<List<Integer>> result = new HashSet<List<Integer>>();

        if (nums == null || nums.length == 0) {
            return new ArrayList(result);
        }

        helper(nums, result, new ArrayList<Integer>(), 0);

        return new ArrayList(result);
    }

    void helper(int[] nums, Set<List<Integer>> result, List<Integer> list, int start) {
        if (list.size() > 1) {
            List<Integer> newList = new ArrayList<Integer>(list);
            result.add(newList);
        }

        for (int i = start; i < nums.length; i++) {
            if (list.size() > 0 && nums[i] < list.get(list.size() - 1)) {
                continue;
            }

            list.add(nums[i]);
            helper(nums, result, list, i + 1);
            list.remove(list.size() - 1);
        }
    }
}

Hope this helps,
Michael