2023年2月20日

力扣刷题——198. 打家劫舍

摘要: 198. 打家劫舍 这也是一道简单的动态规划题目 class Solution { public int rob(int[] nums) { int[] ans = new int[nums.length+1]; ans[0]=0; ans[1]=nums[0]; for(int i = 1; i 阅读全文

posted @ 2023-02-20 13:22 pumpkinsBig 阅读(22) 评论(0) 推荐(0)

力扣刷题——70. 爬楼梯

摘要: 70. 爬楼梯 这题用动态规划写,先求出递推式和边界条件,再用滚动数组的方式写(这样是考虑了空间优化,也可以用一整个数组来做,只不过空间复杂度增大)。 class Solution { public int climbStairs(int n) { int p = 0, m = 1, ans = 0 阅读全文

posted @ 2023-02-20 13:20 pumpkinsBig 阅读(14) 评论(0) 推荐(0)

导航