当前位置:网站首页>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);
}
边栏推荐
- 【信息检索】链接分析
- Install MySQL
- The mouse wheel of xshell/bash/zsh and other terminals is garbled (turn)
- 尊重他人的行为
- Opencv3.2 and opencv2.4 installation
- 【信息检索】分类和聚类的实验
- Abnormal value detection using shap value
- sharding key type not supported
- leetcode:6109. 知道秘密的人数【dp的定义】
- One architecture to complete all tasks - transformer architecture is unifying the AI Jianghu on its own
猜你喜欢
[matlab] summary of conv, filter, conv2, Filter2 and imfilter convolution functions
Test evaluation of software testing
Unity shader learning (3) try to draw a circle
codeforce:C. Sum of Substrings【边界处理 + 贡献思维 + 灵光一现】
【信息检索】分类和聚类的实验
sharding key type not supported
数据仓库面试问题准备
Remove duplicate letters [greedy + monotonic stack (maintain monotonic sequence with array +len)]
【MySQL从入门到精通】【高级篇】(五)MySQL的SQL语句执行流程
Understand chisel language thoroughly 09. Chisel project construction, operation and testing (I) -- build and run chisel project with SBT
随机推荐
Real time data warehouse
Understand chisel language thoroughly 03. Write to the developer of Verilog to chisel (you can also see it without Verilog Foundation)
R语言使用epiDisplay包的dotplot函数通过点图的形式可视化不同区间数据点的频率、使用by参数指定分组参数可视化不同分组的点图分布
ML之shap:基于boston波士顿房价回归预测数据集利用shap值对XGBoost模型实现可解释性案例
为什么图片传输要使用base64编码
Understand chisel language thoroughly 12. Chisel project construction, operation and testing (IV) -- chisel test of chisel test
迅为IMX6Q开发板QT系统移植tinyplay
Excel quickly merges multiple rows of data
The mouse wheel of xshell/bash/zsh and other terminals is garbled (turn)
Can mortgage with housing exclude compulsory execution
Xcode 异常图片导致ipa包增大问题
92.(cesium篇)cesium楼栋分层
尊重他人的行为
ViewModel 初体验
Supprimer les lettres dupliquées [avidité + pile monotone (maintenir la séquence monotone avec un tableau + Len)]
卷积神经网络经典论文集合(深度学习分类篇)
【云原生】我怎么会和这个数据库杠上了?
The failure rate is as high as 80%. What are the challenges on the way of enterprise digital transformation?
What is the difference between Bi financial analysis in a narrow sense and financial analysis in a broad sense?
Understand chisel language thoroughly 06. Chisel Foundation (III) -- registers and counters