当前位置:网站首页>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();
}
}
}
}
边栏推荐
- 继手机之后 报道称三星也削减了电视等家电产品线的产量
- Source NAT address translation and server mapping web page configuration of firewall Foundation
- C语言集合运算
- Synchronization mechanism of dual namenodes
- EMQ helps Qingdao Yanbo build a smart water platform
- d3dx9_ What if 27.dll is lost? d3dx9_ How to repair 27.dll?
- C语言教师工作量管理系统
- Relation and operation of ORM table
- ORM表关系及操作
- C language course design
猜你喜欢

After the mobile phone, it was reported that Samsung also cut the output of TV and other home appliance product lines

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

Julia constructs diagonal matrix
![[the way of programmer training] - 3 Character count statistics](/img/0c/e506571a4b22edc7c02a346909eeab.jpg)
[the way of programmer training] - 3 Character count statistics

Oracle概念三
![[pyGame games] this](/img/3c/e573106ec91441a554cba18d5b2253.png)
[pyGame games] this "eat everything" game is really wonderful? Eat them all? (with source code for free)

Leetcode daily practice (main elements)

Kubernetes基础自学系列 | Ingress API讲解

Alibaba cloud liupeizi: Inspiration from cloud games - innovation on the end

Practice of constructing ten billion relationship knowledge map based on Nebula graph
随机推荐
数据中心表格报表实现定制统计加班请假汇总记录分享
Redis系列2:数据持久化提高可用性
软件测试-测试的概念,单元测试的详细介绍,如何设计测试用例
[fxcg] today's market analysis
Oracle概念二
Missing d3d10 How to repair DLL files? Where can I download d3d10.dll
2/14 preliminary calculation geometry
Domain name binding dynamic IP best practices
List转Table
# Cesium实现卫星在轨绕行
Taishan Office Technology Lecture: the first difficulty is vertical positioning
The time of localdatetime type (2019-11-19t15:16:17) is queried with the time range of Oracle
鴻蒙發力!HDD杭州站·線下沙龍邀您共建生態
字节跳动埋点数据流建设与治理实践
QT audio playback upgrade (7)
智慧风电 | 图扑软件数字孪生风机设备,3D 可视化智能运维
The array of C language is a parameter to pass a pointer
锚文本大量丢失的问题
Kubernetes basic self-study series | introduction to ingress API
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