当前位置:网站首页>Leetcode 47. Full arrangement II
Leetcode 47. Full arrangement II
2022-07-18 22:41:00 【Java full stack R & D Alliance】
Topic transmission address : https://leetcode.cn/problems/permutations-ii/
The code is as follows :
public static List<List<Integer>> permuteUnique(int[] nums) {
Arrays.sort(nums);
List<List<Integer>> result = new ArrayList<>();
if (nums.length == 1) {
result.add(Arrays.asList(nums[0]));
}
for (int i = 0; i < nums.length; i++) {
// In order to get heavy
while (i <= nums.length - 2 && nums[i] == nums[i + 1]) {
i++;
}
int[] restNums = getRestNums(nums, i);
List<List<Integer>> list = permuteUnique(restNums);
for (List<Integer> list1 : list) {
List<Integer> list2 = new ArrayList<>(list1);
list2.add(nums[i]);
result.add(list2);
}
}
return result;
}
private static int[] getRestNums(int[] nums, int i) {
final int[] restNums = new int[nums.length - 1];
for (int n = 0; n < i; n++) {
restNums[n] = nums[n];
}
for (int n = i + 1; n < nums.length; n++) {
restNums[n - 1] = nums[n];
}
return restNums;
}
边栏推荐
- DeepMind最新114页报告《多智能体强化学习中的新兴易货贸易行为》
- 1、shell-echo > 和 echo>>
- [UCOS III source code analysis] - semaphore
- Arduino窗口乱码问题
- 【小程序项目开发-- 京东商城】uni-app之商品列表页面 (上)
- 遠程購買商品Solidity合約
- Web crawler technology creates its own Youdao dictionary
- The mobile terminal is set with fonts smaller than 12px and script labels
- Dior is suspected of plagiarizing Chinese horse face skirt, and the product has been removed from the domestic official website
- J-dict-select-tag drop-down box failure solution
猜你喜欢

Byte 3 finally landed. Please keep this hot noodle Sutra "including free information"

时序事件数据怎么处理?【慕尼黑工业大学博士论文】神经时序点过程(NTPP): 连续时间事件数据建模

Uniapp Basics

alicloud3搭建wordpress

解题-->在线OJ(十六)

DCAT admin code generator application (re edit)

(手工)【sqli-labs58-61】限制注入次数:报错注入、GET注入、字符/数字型
![[UCOS III source code analysis] - message queue](/img/e9/04fb629caa78513a1a6e8a4a98f452.png)
[UCOS III source code analysis] - message queue

UCOSII里面为什么调用OS_ENTER_CRITICAL()或OS_EXIT_CRITICAL()会出错,出错信息为:undeclared identifier `cpu_sr‘

How to take long screenshots in win11? Win11 long screenshot method
随机推荐
Developers share | handwriting operator is not so difficult. I'll teach you to use mindspire to realize adaptive average pooling operator!
1、shell-echo > 和 echo>>
5g NR notes
2-conan 二进制包依赖管理方案
Examen de l'activité | discussion approfondie avec mindstore: comment open source explore l'ensemble du paysage de l'IA
(赛后补题)(伟大的dfs)K - Counting Time
Technology dry goods | mindspire new generation self-developed molecular simulation library: mind sponge
第3章业务功能开发(查看市场活动明细)
数据受限条件下的多模态处理技术综述
Open source ten questions, a quick start guide for community newcomers
2-conan 二進制包依賴管理方案
LCD 显示撕裂解决
Graduation season -- common interview questions in database
surging作者出具压测结果
uCOSIIV2.93移植时为什么会出错,错误信息为undefined symbol ‘_OSTaskReturnHook‘
Accessing local variables in anonymous inner classes
What is pa? Construct the structural element of the virus, Polya, a repeated base sequence
KDD 2017 | metapath2vec: scalable representation learning of heterogeneous graphs
Lingo solves the maximum (small) value of piecewise function
pdf中的超链接,跳转之后,如何返回去? alt + ←