当前位置:网站首页>LeetCode brushing series -- 46. Full arrangement
LeetCode brushing series -- 46. Full arrangement
2022-08-11 07:28:00 【Wooden water in the river island】
Given an array nums without repeating numbers, return all possible permutations of it.You can return answers in any order.
Example 1:
Input: nums = [1,2,3]
Output: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
Example 2:
Input: nums = [0,1]
Output: [[0,1],[1,0]]
Example 3:
Input: nums = [1]
Output: [[1]]
Tip:
1 <= nums.length <= 6
-10 <= nums[i] <= 10
All integers in nums are different from each other
Source: LeetCode
Link: https://leetcode.cn/problems/permutations
Thinking:
This question can be backtracked
java code:
class Solution {public List> permute(int[] nums) {List> result = new ArrayList<>();fullPermutation(nums, result, new LinkedList<>());return result;}public void fullPermutation(int[] nums, List> result, List subList) {// Indicates that all elements have been arranged in this arrangementif (subList.size() == nums.length) {result.add(new LinkedList<>(subList));return;}for (int num : nums) {if (subList.contains(num)) {continue;}subList.add(num);fullPermutation(nums, result, subList);subList.remove(subList.size() - 1);}}}
边栏推荐
- Unity游戏排行榜的制作与优化
- HCIP MGRE\OSPF Comprehensive Experiment
- 软件测试主要做什么工作,难不难?
- 抖音分享口令url API工具
- 损失函数——交叉熵
- SQL sliding window
- PIXHAWK飞控使用RTK
- Spatial Pyramid Pooling -Spatial Pyramid Pooling (including source code)
- Edge 提供了标签分组功能
- sql--Users who have purchased more than 3 times (inclusive) within 7 days (including the current day), and the purchase amount in the past 7 days exceeds 1,000
猜你喜欢
Get Pinduoduo product information operation details
Discourse's Close Topic and Reopen Topic
1688 product interface
Taobao sku API interface (PHP example)
《Generative Adversarial Networks》
已解决EROR 1064 (42000): You have an error in. your SOL syntax. check the manual that corresponds to yo
《Show and Tell: A Neural Image Caption Generator》论文解读
空间金字塔池化 -Spatial Pyramid Pooling(含源码)
MySQL 版本升级心得
[损失函数]——均方差
随机推荐
Strongly recommend an easy-to-use API interface
SQL sliding window
2022-08-09 第四小组 修身课 学习笔记(every day)
如何选择专业、安全、高性能的远程控制软件
已解决EROR 1064 (42000): You have an error in. your SOL syntax. check the manual that corresponds to yo
STM32CUBEIDE(11)----输出PWM及修改PWM频率与占空比
1688商品详情接口
jar服务导致cpu飙升问题-带解决方法
从 dpdk-20.11 移植 intel E810 百 G 网卡 pmd 驱动到 dpdk-16.04 中
求过去半年内连续30天以上每天都有1000元以上成交的商铺
golang fork 进程的三种方式
网络电话软件或迎整顿 “免费”通话须迈安全关
Taobao API common interface and acquisition method
Attitude solution - gyroscope + Euler method
Implement general-purpose, high-performance sorting and quicksort optimizations
Daily sql-seek the sum of successful investments in 2016
每日sql--统计员工近三个月的总薪水(不包括最新一个月)
redis + lua实现分布式接口限流实现方案
Daily sql: request for friend application pass rate
抖音API接口大全