mirror of
https://github.com/krahets/hello-algo.git
synced 2026-04-03 02:30:25 +08:00
Fix code naming style.
This commit is contained in:
@@ -8,18 +8,18 @@ namespace hello_algo.chapter_dynamic_programming;
|
||||
|
||||
public class climbing_stairs_dfs {
|
||||
/* 搜索 */
|
||||
public int Dfs(int i) {
|
||||
public int DFS(int i) {
|
||||
// 已知 dp[1] 和 dp[2] ,返回之
|
||||
if (i == 1 || i == 2)
|
||||
return i;
|
||||
// dp[i] = dp[i-1] + dp[i-2]
|
||||
int count = Dfs(i - 1) + Dfs(i - 2);
|
||||
int count = DFS(i - 1) + DFS(i - 2);
|
||||
return count;
|
||||
}
|
||||
|
||||
/* 爬楼梯:搜索 */
|
||||
public int ClimbingStairsDFS(int n) {
|
||||
return Dfs(n);
|
||||
return DFS(n);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace hello_algo.chapter_dynamic_programming;
|
||||
|
||||
public class climbing_stairs_dfs_mem {
|
||||
/* 记忆化搜索 */
|
||||
public int Dfs(int i, int[] mem) {
|
||||
public int DFS(int i, int[] mem) {
|
||||
// 已知 dp[1] 和 dp[2] ,返回之
|
||||
if (i == 1 || i == 2)
|
||||
return i;
|
||||
@@ -16,7 +16,7 @@ public class climbing_stairs_dfs_mem {
|
||||
if (mem[i] != -1)
|
||||
return mem[i];
|
||||
// dp[i] = dp[i-1] + dp[i-2]
|
||||
int count = Dfs(i - 1, mem) + Dfs(i - 2, mem);
|
||||
int count = DFS(i - 1, mem) + DFS(i - 2, mem);
|
||||
// 记录 dp[i]
|
||||
mem[i] = count;
|
||||
return count;
|
||||
@@ -27,7 +27,7 @@ public class climbing_stairs_dfs_mem {
|
||||
// mem[i] 记录爬到第 i 阶的方案总数,-1 代表无记录
|
||||
int[] mem = new int[n + 1];
|
||||
Array.Fill(mem, -1);
|
||||
return Dfs(n, mem);
|
||||
return DFS(n, mem);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
Reference in New Issue
Block a user