国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Permutations II

2019-11-06 08:50:37
字體:
來源:轉載
供稿:網友

Given a list of numbers with duplicate number in it. Find all unique permutations.

class Solution { /** * @param nums: A list of integers. * @return: A list of unique permutations. */ public List<List<Integer>> permuteUnique(int[] nums) { List<List<Integer>> results = new ArrayList<>(); if (nums == null) { return results; } if (nums.length == 0) { results.add(new ArrayList<Integer>()); return results; } List<Integer> result = new ArrayList<>(); Set<List<Integer>> hash = new HashSet<>(); int[] visited = new int[nums.length]; dfsHelper(nums, visited, results, result, hash); return results; } PRivate void dfsHelper(int[] nums, int[] visited, List<List<Integer>> results, List<Integer> result, Set<List<Integer>> hash) { if (result.size() == nums.length ) { List<Integer> temp = new ArrayList<Integer>(result); if (!hash.contains(temp)) { results.add(temp); hash.add(temp); } } for (int i = 0; i < nums.length; i++) { if (visited[i] == 1) { continue; } result.add(nums[i]); visited[i] = 1; dfsHelper(nums, visited, results, result, hash); result.remove(result.size() - 1); visited[i] = 0; } }}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 抚松县| 石家庄市| 耒阳市| 石家庄市| 郓城县| 阳曲县| 从江县| 万年县| 祁东县| 阿克苏市| 昂仁县| 漳平市| 五寨县| 武功县| 蛟河市| 赤壁市| 美姑县| 出国| 开阳县| 喜德县| 玉环县| 昌都县| 斗六市| 阿拉善盟| 盈江县| 衡山县| 固原市| 寻乌县| 海南省| 曲松县| 会东县| 名山县| 剑阁县| 富宁县| 宜章县| 中阳县| 漳州市| 盐亭县| 务川| 柏乡县| 永和县|