当前位置:网站首页>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);}}}
边栏推荐
- 基于FPGA的FIR滤波器的实现(5)— 并行结构FIR滤波器的FPGA代码实现
- STM32CUBEIDE(11)----输出PWM及修改PWM频率与占空比
- redis + lua实现分布式接口限流实现方案
- 2022-08-09 第四小组 修身课 学习笔记(every day)
- 皮质-皮质网络的多尺度交流
- Attitude solution - gyroscope + Euler method
- Daily sql: request for friend application pass rate
- 矩阵分析——微分、积分、极限
- 什么是Inductive learning和Transductive learning
- 每日sql-统计各个专业人数(包括专业人数为0的)
猜你喜欢
Douyin API interface
京东商品详情API调用实例讲解
Douyin API interface
空间金字塔池化 -Spatial Pyramid Pooling(含源码)
ROS 服务通信理论模型
Discourse 的关闭主题(Close Topic )和重新开放主题
JD.com product details API call example explanation
prometheus学习4Grafana监控mysql&blackbox了解
HCIP MPLS/BGP Comprehensive Experiment
Taobao sku API interface (PHP example)
随机推荐
numpy和tensor增加或删除一个维度
每日sql - 判断+聚合
拼多多API接口(附上我的可用API)
concept noun
拼多多api接口应用示例
抖音分享口令url API工具
Amazon Get AMAZON Product Details API Return Value Description
How to choose professional, safe and high-performance remote control software
下一代 无线局域网--强健性
一个小时快速熟悉MySQL基本用法
prometheus学习5altermanager
Daily sql - judgment + aggregation
Go语言实现Etcd服务发现(Etcd & Service Discovery & Go)
每日sql-员工奖金过滤和回答率排序第一
Especially the redis
《Generative Adversarial Networks》
unable to extend table xxx by 1024 in tablespace xxxx
Pinduoduo API interface (attach my available API)
你是如何做好Unity项目性能优化的
jar服务导致cpu飙升问题-带解决方法