mirror of
https://github.com/krahets/hello-algo.git
synced 2025-07-05 13:15:30 +08:00
feat: add dynamic programming code for JS and TS (#692)
* fix: Correcting typos * Add JavaScript and TypeScript code of dynamic programming. * fix: Code Style * Change ==/!= to ===/!== * Create const by default, change to let if necessary. * style fix: Delete unnecessary defined type
This commit is contained in:
@ -104,7 +104,7 @@ public class min_path_sum {
|
||||
|
||||
// 暴力搜索
|
||||
int res = minPathSumDFS(grid, n - 1, m - 1);
|
||||
System.out.println("从左上角到右下角的做小路径和为 " + res);
|
||||
System.out.println("从左上角到右下角的最小路径和为 " + res);
|
||||
|
||||
// 记忆化搜索
|
||||
int[][] mem = new int[n][m];
|
||||
@ -112,14 +112,14 @@ public class min_path_sum {
|
||||
Arrays.fill(row, -1);
|
||||
}
|
||||
res = minPathSumDFSMem(grid, mem, n - 1, m - 1);
|
||||
System.out.println("从左上角到右下角的做小路径和为 " + res);
|
||||
System.out.println("从左上角到右下角的最小路径和为 " + res);
|
||||
|
||||
// 动态规划
|
||||
res = minPathSumDP(grid);
|
||||
System.out.println("从左上角到右下角的做小路径和为 " + res);
|
||||
System.out.println("从左上角到右下角的最小路径和为 " + res);
|
||||
|
||||
// 空间优化后的动态规划
|
||||
res = minPathSumDPComp(grid);
|
||||
System.out.println("从左上角到右下角的做小路径和为 " + res);
|
||||
System.out.println("从左上角到右下角的最小路径和为 " + res);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user