摘要:
动态规划 class Solution { public int numDecodings(String s) { if (s.charAt(0) == '0'){ return 0; } int n = s.length(); /** * 定义dp[i]为长度为i的子串解码的总数,字符串为空默认也 阅读全文
摘要:
动态规划 class Solution { public int minPathSum(int[][] grid) { int m = grid.length; int n = grid[0].length; /** * dp[i][j]定义为从起点出发到当前这个点的最小路径和 * 初始值dp[0] 阅读全文
摘要:
动态规划 class Solution { public int uniquePaths(int m, int n) { /** * 定义dp[i][j]为到达该坐标的路径总和 * 第一行和第一列的坐标,只能从左或者上进行访问,其值初始化都为1 */ int[][] dp = new int[m][ 阅读全文
摘要:
动态规划 class Solution { public int minCostClimbingStairs(int[] cost) { /** * 最少有两个台阶,因此不用提前判断dp数组空指针异常的情况 * 索引从0开始 * dp[i]指的是到达第i个台阶并且向上爬所需要的最小费用 */ int 阅读全文