-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
27 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
"use strict"; | ||
|
||
function solution(n) { | ||
let arr = []; | ||
let checkArr = Array.from({ length: n + 1 }, () => 0); | ||
|
||
// 부분집합 구하기 | ||
function dfs(v) { | ||
if (v === n + 1) { | ||
let value = ""; | ||
for (let i = 1; i <= n; i++) { | ||
if (checkArr[i] === 1) value += i + " "; | ||
} | ||
if (value.length > 0) arr.push(value.trim()); | ||
} else { | ||
checkArr[v] = 1; // 포함 시킴 | ||
dfs(v + 1); // 왼쪽 | ||
checkArr[v] = 0; // 포함시키지 않음 | ||
dfs(v + 1); // 오른쪽 | ||
} | ||
} | ||
dfs(1); | ||
return arr; | ||
} | ||
|
||
console.log(solution(3)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters