mirror of
https://github.com/krahets/hello-algo.git
synced 2026-11-01 18:55:23 +08:00
* feat(ko): add the complete Korean online edition * Use UTF-8 for Python CI output on Windows * Remove print-book promotion from the Korean site * fix(ko): preserve emphasis before Korean particles
25 lines
591 B
JavaScript
25 lines
591 B
JavaScript
/**
|
|
* File: climbing_stairs_dfs.js
|
|
* Created Time: 2023-07-26
|
|
* Author: yuan0221 ([email protected])
|
|
*/
|
|
|
|
/* 탐색 */
|
|
function dfs(i) {
|
|
// dp[1]과 dp[2]는 이미 알고 있으므로 해당 값을 반환한다
|
|
if (i === 1 || i === 2) return i;
|
|
// dp[i] = dp[i-1] + dp[i-2]
|
|
const count = dfs(i - 1) + dfs(i - 2);
|
|
return count;
|
|
}
|
|
|
|
/* 계단 오르기: 탐색 */
|
|
function climbingStairsDFS(n) {
|
|
return dfs(n);
|
|
}
|
|
|
|
/* 실행 코드 */
|
|
const n = 9;
|
|
const res = climbingStairsDFS(n);
|
|
console.log(`${n}개의 계단을 오르는 방법은 총 ${res}가지이다`);
|