当前位置:网站首页>LeetCode_ 47_ Full arrangement II
LeetCode_ 47_ Full arrangement II
2022-07-23 13:51:00 【Fitz1318】
Topic link
Title Description
Given a sequence that can contain repeating numbers nums , In any order Returns all non repeating permutations .
Example 1:
Input :nums = [1,1,2]
Output :
[[1,1,2],
[1,2,1],
[2,1,1]]
Example 2:
Input :nums = [1,2,3]
Output :[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
Tips :
1 <= nums.length <= 8-10 <= nums[i] <= 10
Their thinking
Law 1 : backtracking + No pruning
Is to traverse all possibilities , Then go heavy.
AC Code
Law 1
class Solution {
boolean[] flag;
List<Integer> path = new ArrayList<>();
List<List<Integer>> ans = new ArrayList<>();
public List<List<Integer>> permuteUnique(int[] nums) {
flag = new boolean[nums.length];
backTracing(nums);
return ans;
}
private void backTracing(int[] nums) {
if (path.size() == nums.length && !ans.contains(path)) {
ans.add(new ArrayList<>(path));
return;
}
for (int i = 0; i < nums.length; i++) {
if (flag[i]) {
continue;
}
path.add(nums[i]);
flag[i] = true;
backTracing(nums);
path.remove(path.size() - 1);
flag[i] = false;
}
}
}
边栏推荐
- 回溯法解决 八皇后问题
- High school Chinese teaching material examination outline
- Interviewer: have you learned about the underlying implementation of reentrantlock? tell us your opinion
- 数据库系统原理与应用教程(040)—— MySQL 查询(二):设置要查询的列名或表达式
- LeetCode_52_N皇后Ⅱ
- docker redis
- 数据库系统原理与应用教程(052)—— MySQL 的数据完整性(十四):交叉表查询(行列转换)
- 数据库系统原理与应用教程(051)—— MySQL 查询(十三):DML 语句中使用查询
- 浅谈Anroid设备的CPU类型以及so文件的放置目录
- Point target simulation of SAR imaging (II) -- matlab simulation
猜你喜欢

了解canvas

Learn to use canvas to build line chart, bar chart and pie chart

Événements courants de la souris et du clavier

如何保证消息的可靠传输?如果消息丢了会怎么办

Learn about canvas

CSDN recommended template

Optimising a 3D convolutional neural network for head and neck computed tomography segmentation with

Remote editing and debugging with vscode

Introduction to radar part vii 2 imaging method

回溯法解决 八皇后问题
随机推荐
常用的鼠標事件和鍵盤事件
-20: +usecgroupmemorylimitforheap failed to create virtual machine problem
Shell运算符、$((运算式))” 或 “$[运算式]、expr方法、条件判断、test condition、[ condition ]、两个整数之间比较、按照文件权限进行判断、按照文件类型进行判断
Convergence of abnormal integral
浅谈Anroid设备的CPU类型以及so文件的放置目录
单例模式实现及防止反射与序列化
[cocos creator] spin animation, monitoring and playback end
Unity about local loading pictures involves webrequest or byte
在虚拟环境下使用pip时默认使用系统环境的pip该怎么办
Probability meditation: 2. The quantitative rules
PHP获取当前时间戳三位毫秒 - 毫秒时间戳
腾讯MMKV的原理与实现
Smart canteen data analysis system
Kotlin - 挂起函数 suspend
General contents of radar introduction column
QT creator.Pro file adds the corresponding library according to the kit
Kept dual machine hot standby
Starfish OS:以现实为纽带,打造元宇宙新范式
Running matlab program on GPU
数据库系统原理与应用教程(049)—— MySQL 查询(十一):子查询