当前位置:网站首页>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);
}
边栏推荐
- MySQL的存储过程练习题
- Vscode common plug-ins summary
- Data center concept
- One architecture to complete all tasks - transformer architecture is unifying the AI Jianghu on its own
- MySQL的触发器
- 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
- Real time data warehouse
- QT how to detect whether the mouse is on a control
- Use of arouter
- Redis daily notes
猜你喜欢

Use of tiledlayout function in MATLAB

codeforce:C. Sum of Substrings【边界处理 + 贡献思维 + 灵光一现】

Leetcode 61: 旋转链表

The implementation of OSD on rk1126 platform supports color translucency and multi-channel support for Chinese

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

Rich text editing: wangeditor tutorial

使用CLion编译OGLPG-9th-Edition源码

2022 practice questions and mock exams for the main principals of hazardous chemical business units

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

Why should Base64 encoding be used for image transmission
随机推荐
Abnormal value detection using shap value
R language ggplot2 visualization: gganimate package creates dynamic line graph animation (GIF) and uses transition_ The reveal function displays data step by step along a given dimension in the animat
MySQL之详解索引
实时数据仓库
The mouse wheel of xshell/bash/zsh and other terminals is garbled (turn)
【信息检索】分类和聚类的实验
R language uses bwplot function in lattice package to visualize box plot and par Settings parameter custom theme mode
leetcode:6110. 网格图中递增路径的数目【dfs + cache】
如何游戏出海代运营、游戏出海代投
RK1126平台OSD的实现支持颜色半透明度多通道支持中文
流行框架:Glide的使用
R language uses follow up of epidisplay package The plot function visualizes the longitudinal follow-up map of multiple ID (case) monitoring indicators, and uses stress The col parameter specifies the
Xcode 异常图片导致ipa包增大问题
Oppo find N2 product form first exposure: supplement all short boards
Idea shortcut keys
Vscode common plug-ins summary
Map of mL: Based on Boston house price regression prediction data set, an interpretable case of xgboost model using map value
AI与生命科学
opencv3.2 和opencv2.4安装
The failure rate is as high as 80%. What are the challenges on the way of enterprise digital transformation?