mirror of
https://github.com/krahets/hello-algo.git
synced 2026-11-02 03:05:24 +08:00
* Retranslate the complete Japanese online edition from Chinese * Fit Japanese homepage labels and localize heading permalinks * Point Japanese contribution instructions to the Japanese preview * Replace locale conditionals with multilingual UI tables
25 lines
578 B
JavaScript
25 lines
578 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} 通り`);
|