当前位置:网站首页>Leetcode t47: full arrangement II
Leetcode t47: full arrangement II
2022-07-04 14:23:00 【Fan Qianzhi】
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
Ideas
utilize HashMap duplicate removal
Code
int n;
int[] a;
Map<List<Integer>, Integer> res;
void prem(int cur) {
if(cur == n) {
List<Integer> lis = new ArrayList<Integer>();
for(int x: a) lis.add(x);
res.put(lis, 1);
} else {
for(int i = cur; i < n; i++) {
int t = a[i]; a[i] = a[cur]; a[cur] = t;
prem(cur+1);
t = a[i]; a[i] = a[cur]; a[cur] = t;
}
}
}
public List<List<Integer>> permuteUnique(int[] nums) {
a = nums;
n = nums.length;
res = new HashMap<List<Integer>, Integer>();
prem(0);
return new ArrayList<List<Integer>>(res.keySet());
}
void test() throws IOException {
Reader cin = new Reader();
int[] a = {
1,2,3};
permuteUnique(a);
}
边栏推荐
- 【算法leetcode】面试题 04.03. 特定深度节点链表(多语言实现)
- Leetcode 61: 旋转链表
- R language uses dplyr package group_ The by function and the summarize function calculate the mean and standard deviation of the target variables based on the grouped variables
- golang fmt. Printf() (turn)
- Code hoof collection of wonderful secret place
- R语言使用dplyr包的group_by函数和summarise函数基于分组变量计算目标变量的均值、标准差
- LifeCycle
- Use of arouter
- Ws2818m is packaged in cpc8. It is a special circuit for three channel LED drive control. External IC full-color double signal 5v32 lamp programmable LED lamp with outdoor engineering
- Rich text editing: wangeditor tutorial
猜你喜欢

数据中台概念

leetcode:6109. 知道秘密的人数【dp的定义】

Understand chisel language thoroughly 10. Chisel project construction, operation and testing (II) -- Verilog code generation in chisel & chisel development process

Leetcode T48:旋转图像

RK1126平台OSD的实现支持颜色半透明度多通道支持中文

docker-compose公网部署redis哨兵模式

flink sql-client.sh 使用教程

【MySQL从入门到精通】【高级篇】(五)MySQL的SQL语句执行流程

Xcode 异常图片导致ipa包增大问题

sql优化之explain
随机推荐
【MySQL从入门到精通】【高级篇】(四)MySQL权限管理与控制
Leetcode 61: 旋转链表
Fs4059c is a 5V input boost charging 12.6v1.2a. Inputting a small current to three lithium battery charging chips will not pull it dead. The temperature is 60 ° and 1000-1100ma is recommended
MySQL之详解索引
Oppo find N2 product form first exposure: supplement all short boards
AI and Life Sciences
sharding key type not supported
Opencv3.2 and opencv2.4 installation
R语言使用epiDisplay包的dotplot函数通过点图的形式可视化不同区间数据点的频率、使用by参数指定分组参数可视化不同分组的点图分布
Chapter 17 process memory
Code hoof collection of wonderful secret place
Unity shader learning (3) try to draw a circle
R language dplyr package summary_ If function calculates the mean and median of all numerical data columns in dataframe data, and summarizes all numerical variables based on conditions
Test process arrangement (2)
PHP log debugging
Product identification of intelligent retail cabinet based on paddlex
Assertion of unittest framework
AI与生命科学
Can mortgage with housing exclude compulsory execution
golang fmt. Printf() (turn)