当前位置:网站首页>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);
}
边栏推荐
- 聊聊保证线程安全的 10 个小技巧
- 第十七章 进程内存
- 实时数据仓库
- Basic mode of service mesh
- Opencv3.2 and opencv2.4 installation
- R language uses the DOTPLOT function of epidisplay package to visualize the frequency of data points in different intervals in the form of point graph, and uses the by parameter to specify the groupin
- C # WPF realizes the real-time screen capture function of screen capture box
- MySQL的触发器
- Map of mL: Based on Boston house price regression prediction data set, an interpretable case is realized by using the map value to the LIR linear regression model
- How to package QT and share exe
猜你喜欢
随机推荐
Understand chisel language thoroughly 12. Chisel project construction, operation and testing (IV) -- chisel test of chisel test
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?
Remove duplicate letters [greedy + monotonic stack (maintain monotonic sequence with array +len)]
Supprimer les lettres dupliquées [avidité + pile monotone (maintenir la séquence monotone avec un tableau + Len)]
Visual Studio调试方式详解
File creation, writing, reading, deletion (transfer) in go language
数据中台概念
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
学内核之三:使用GDB跟踪内核调用链
NowCoder 反转链表
Test evaluation of software testing
R语言使用lattice包中的bwplot函数可视化箱图(box plot)、par.settings参数自定义主题模式
Real time data warehouse
GCC【6】- 编译的4个阶段
Common content type correspondence table
去除重複字母[貪心+單調棧(用數組+len來維持單調序列)]
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
MySQL之详解索引
Install and use MAC redis, connect to remote server redis

![递增的三元子序列[贪心训练]](/img/92/7efd1883c21c0e804ffccfb2231602.png)







