当前位置:网站首页>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);}}}
边栏推荐
- prometheus学习4Grafana监控mysql&blackbox了解
- 如何选择专业、安全、高性能的远程控制软件
- 【推荐系统】:协同过滤和基于内容过滤概述
- Do not add the is prefix to the variables of the boolean type in the POJO class of the Alibaba specification
- Daily SQL - find each of the students school gpa minimum (window)
- 抖音获取douyin分享口令url API 返回值说明
- Internet phone software or consolidation of attack must be "free" calls security clearance
- Daily sql: request for friend application pass rate
- Amazon API interface Daquan
- 抖音关键词搜索商品-API工具
猜你喜欢
随机推荐
皮质-皮质网络的多尺度交流
[损失函数]——均方差
抖音API接口
OA project meeting notice (query & whether attending & feedback for details)
每日sql-统计各个专业人数(包括专业人数为0的)
Waldom Electronics宣布成立顾问委员会
下一代 无线局域网--强健性
Unity底层是如何处理C#的
Unity3D 学习路线?
Go语言实现Etcd服务发现(Etcd & Service Discovery & Go)
unable to extend table xxx by 1024 in tablespace xxxx
mmdetection的安装和训练、测试didi数据集的步骤(含结果)
求过去半年内连续30天以上每天都有1000元以上成交的商铺
损失函数——交叉熵
李沐d2l(十)--卷积层Ⅰ
sql--7天内(含当天)购买次数超过3次(含),且近7天的购买金额超过1000的用户
Resolved EROR 1064 (42000): You have an error in. your SOL syntax. check the manual that corresponds to yo
daily sql - user retention rate for two days
强烈推荐一款好用的API接口
Daily sql: request for friend application pass rate