Skip to content

Commit 5d93b0f

Browse files
committed
feat: 문제풀이 추가
1 parent ba7cfff commit 5d93b0f

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

climbing-stairs/hwanmini.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// 시간복잡도 O(n)
2+
// 공간복잡도 O(n)
3+
4+
/**
5+
* @param {number} n
6+
* @return {number}
7+
*/
8+
var climbStairs = function(n) {
9+
const stairs = [1, 2]
10+
11+
for (let i = 2; i < n; i++) {
12+
stairs[i] = stairs[i-1] + stairs[i-2]
13+
}
14+
15+
return stairs[n-1]
16+
};
17+
18+
console.log(climbStairs(5))

combination-sum/hwanmini.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// 시간복잡도: O(c^t)
2+
// 공간복잡도: O(t)
3+
4+
/**
5+
* @param {number[]} candidates
6+
* @param {number} target
7+
* @return {number[][]}
8+
*/
9+
var combinationSum = function(candidates, target) {
10+
const result = [];
11+
12+
const dfs = (startIdx, subset = [], sum = 0) => {
13+
if (sum > target) return;
14+
if (sum === target) {
15+
result.push([...subset]);
16+
return;
17+
}
18+
19+
20+
for (let i = startIdx; i < candidates.length; i++) {
21+
subset.push(candidates[i]);
22+
dfs(i, subset, sum + candidates[i]);
23+
subset.pop();
24+
}
25+
};
26+
27+
dfs(0);
28+
29+
return result;
30+
};
31+
32+
console.log(combinationSum([2, 3, 6, 7], 7));

0 commit comments

Comments
 (0)