当前位置:网站首页>Leetcode 46 Full Permutation
Leetcode 46 Full Permutation
2022-06-27 16:58:00 【chenyson】
difficulty : secondary
The frequency of :119
subject :
Give an array without duplicate numbers nums , Back to its All possible permutations . You can In any order Return to the answer .
Their thinking : Backtracking traversal
class Solution {
public List<List<Integer>> permute(int[] nums) {
// The length of the array 、 Number of children
int len=nums.length;
// Create the final result res
List<List<Integer>> res=new ArrayList<>();
// If the array length is 0, Then there is no need to arrange
if(len==0) return res;
// take path Put it in deque in , Because Deque You can take out the front and back
Deque<Integer> path=new ArrayDeque<>(len);
// Of the tag flag, If this number is used , Mark for 1, Not used yet 0
boolean[] flag=new boolean[len];
//DFS Traverse It's actually doing LEN Time DFS Traverse
DFS(nums,len,0,path,flag,res);
return res;
}
public void DFS(int[] nums,int len,int depth,Deque<Integer> path, boolean[] flag
, List<List<Integer>> res){
if(len==depth){
res.add(new ArrayList<>(path));
return ;
}
//len The second traversal is highlighted here || And one. DFS Trees len Three elements are also highlighted here
for(int i=0;i<len;i++){
// If flag yes 0, That is, this number has not been used yet
if(!flag[i]){
// If you haven't used it, use this number as follows
path.addLast(nums[i]);// The root node
flag[i]=true;
DFS(nums,len,depth+1,path,flag,res);
flag[i]=false;
path.removeLast();
}
}
}
}
边栏推荐
- Delete duplicate elements in the sorting linked list
- Bit. Store: long bear market, stable stacking products may become the main theme
- List转Table
- Data center table reports realize customized statistics, overtime leave summary record sharing
- d3dx9_ How to repair 25.dll? d3dx9_ 25.dll where to download
- 如何提升IT电子设备效能管理
- 开源二三事|ShardingSphere 与 Database Mesh 之间不得不说的那些事
- 郎酒两大王牌产品成都联动共振,持续带动光瓶酒消费浪潮
- 软件测试-测试的概念,单元测试的详细介绍,如何设计测试用例
- [multithreading] thread communication scheduling, waiting set wait(), notify()
猜你喜欢

Redis系列2:数据持久化提高可用性

智慧风电 | 图扑软件数字孪生风机设备,3D 可视化智能运维

What is RPC

郎酒两大王牌产品成都联动共振,持续带动光瓶酒消费浪潮

Autodesk Navisworks 2022软件安装包下载及安装教程

Determine the maximum number of specific words in a string

开源二三事|ShardingSphere 与 Database Mesh 之间不得不说的那些事
P. Simple application of a.r.a method in Siyuan (friendly testing)

Oracle概念二

Alibaba cloud liupeizi: Inspiration from cloud games - innovation on the end
随机推荐
一个机器人位于一个 m x n 网格的左上角 。机器人每次只能向下或者向右移动一步。机器人试图达到网格的右下角。问总共有多少条不同的路径?【LeetCodeHot100】
[pygame Games] ce jeu "eat Everything" est fantastique? Tu manges tout? (avec code source gratuit)
Relation and operation of ORM table
The European unified charging specification act was passed before the end of the year, and it is planned to expand to products such as laptop and keyboard
d3dx9_ How to repair 33.dll? d3dx9_ What if 33.dll is lost?
Etcd可视化工具:Kstone部署(一),基于Helm快速部署
Unity 阴影——阴影平坠(Shadow pancaking)
d3dx9_ How to repair 38.dll? d3dx9_ 38. How to download a missing DLL?
SQLite net (SQLite is used by unity, WPF and WinForm)
模拟进程调度
阿里云刘珅孜:云游戏带来的启发——端上创新
Related configuration commands of Huawei LACP
C语言教师工作量管理系统
开源二三事|ShardingSphere 与 Database Mesh 之间不得不说的那些事
Detailed explanation of various GPIO input and output modes (push-pull, open drain, quasi bidirectional port)
C语言课程设计
What are the password requirements for waiting insurance 2.0? What are the legal bases?
Missing d3d10 How to repair DLL files? Where can I download d3d10.dll
米哈游起诉五矿信托,后者曾被曝产品暴雷
Community sharing jumpserver in the eyes of senior open source users: a fortress machine for "Crazy" iteration