Recursion and non-recursion Java solution for your reference
Two solution, recursion and non-recursion:\n\nRecursion solution:\n\n    public class Solution {\n        Set hash = new HashSet<>();\n        List> res = new A
Two solution, recursion and non-recursion:\n\nRecursion solution:\n\n    public class Solution {\n        Set<Integer> hash = new HashSet<>();\n        List<List<Integer>> res = new ArrayList<>();\n        int n;\n        int[] nums;\n        \n        public void search(List<Integer> l, int p) {\n            if (p == n) {\n                int h = l.hashCode();\n                if (!hash.contains(h)) {\n                    hash.add(h);\n                    res.add(new ArrayList<>(l));\n                }\n                return;\n            }\n            l.add(nums[p]);\n            search(l, p+1);\n            l.remove(l.size()-1);\n            search(l, p+1);\n        }\n        \n        public List<List<Integer>> subsetsWithDup(int[] nums) {\n            this.n = nums.length; this.nums = nums;\n            Arrays.sort(nums);\n            search(new ArrayList<Integer>(), 0);\n            return res;\n        }\n    }\n\nNon-recursion solution:\n\n    public class Solution {\n        public List<List<Integer>> subsetsWithDup(int[] nums) {\n            List<List<Integer>> res = new ArrayList<>();\n            List<Integer> temp = new ArrayList<>();\n            res.add(temp);\n            Arrays.sort(nums);\n            int l = 0, k;\n            for (int i = 0; i < nums.length; i++) {\n                if (i == 0 || nums[i] != nums[i-1])\n                    l = res.size();\n                k = res.size();\n                for (int j = k-l; j < k; j++) {\n                    temp = new ArrayList<>(res.get(j));\n                    temp.add(nums[i]);\n                    res.add(temp);\n                }\n            }\n            return res;\n        }\n    }
['Java']