Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- Hill Climbing
- 문자열
- 배포
- lightsailor
- computerscience
- typescript
- 알고리즘
- 코드
- Simulated Annealing
- multer-s3
- CS
- 컴퓨터공학
- Local Search
- node배포
- 문자열처리
- 철학
- Search Algorithm
- 파이썬
- 컴퓨터과학
- node.js
- AWS
Archives
- Today
- Total
지식의모듈화
[LeetCode][JavaScript] DFS Problems 본문
46. Permutations
/**
* @param {number[]} nums
* @return {number[][]}
*/
var permute = function(nums) {
let visited= new Array(nums.length).fill(false);
const ans =[];
function dfs(current){
if (current.length===nums.length){
ans.push(current);
}
for(let i=0;i<nums.length;i++){
if(!visited[i]){
visited[i]=true;
dfs([...current,nums[i]])
visited[i]=false;
}
}
}
dfs([])
// console.log(ans)
return ans;
};
Permutation의 기본은 DFS다...
'PS > LeetCode' 카테고리의 다른 글
[Leetcode][Javascript] 36. Valid Sudoku (0) | 2022.08.17 |
---|---|
[LeetCode][Javascript] LinkedList Problems (0) | 2022.08.05 |
[LeetCode][Javascript] Binary Search Tree Problems (0) | 2022.08.04 |
[CoderPad Interview] Problem 77 [Easy] (0) | 2022.08.04 |
[LeetCode][JavaScript] 1. TwoSum (0) | 2022.08.04 |