当前位置:网站首页>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);}}}
边栏推荐
猜你喜欢

皮质-皮质网络的多尺度交流

什么是Inductive learning和Transductive learning

拼多多API接口大全

姿态解算-陀螺仪+欧拉法

基于FPGA的FIR滤波器的实现(5)— 并行结构FIR滤波器的FPGA代码实现

daily sql - query for managers and elections with at least 5 subordinates

空间金字塔池化 -Spatial Pyramid Pooling(含源码)

exness:黄金1800关口遇阻,静待美国CPI出炉

Strongly recommend an easy-to-use API interface

When MySQL uses GROUP BY to group the query, the SELECT query field contains non-grouping fields
随机推荐
导航定位中的坐标系
《猪猪1984》NFT 作品集将上线 The Sandbox 市场平台
Coordinate system in navigation and positioning
maxwell concept
LabelEncoder和LabelBinarizer的区别
sql--7天内(含当天)购买次数超过3次(含),且近7天的购买金额超过1000的用户
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
buu—Re(5)
docker安装mysql5.7(仅供测试使用)
HCIA knowledge review
2022-08-09 第四小组 修身课 学习笔记(every day)
[损失函数]——均方差
微信小程序功能上新(2022.06.01~2022.08.04)
Taobao API interface reference
技术分享 | 实战演练接口自动化如何处理 Form 请求?
Douyin API interface
联想集团:2022/23财年第一季度业绩
从 dpdk-20.11 移植 intel E810 百 G 网卡 pmd 驱动到 dpdk-16.04 中
PIXHAWK飞控使用RTK
opencv实现数据增强(图片+标签)平移,翻转,缩放,旋转