Day34: 62. Unique Paths, 63. Unique Paths II

62. Unique Pathsicon-default.png?t=N7T8https://leetcode.com/problems/unique-paths/description/题目难度:Medium

做题情况:顺滑

解题思路:

1. Initializatioin of the DP Table: start by creating a 2D list 'DP' of dimesions 'm' by 'n' where each cell is initially set to zero.

2. Setting Base Cases: The first row and the first column are filled with 1s because there's only one way to get to any cell in the first row or the first column—by moving either right (for the first row) or down (for the first column).

3. Filling the DP Table: For each cell in the grid that is not on the top row or the first column, the number of ways to reach that cell is the sum of the number of ways to reach the cell directly above it and the cell directly to the left of it.

时间复杂度:O(m * n)

空间复杂度:O(m * n)

63. Unique Paths IIicon-default.png?t=N7T8https://leetcode.com/problems/unique-paths-ii/description/题目难度:Medium

做题情况:顺滑

解题思路:和上一题非常像,但是在设置初始值时,如果在最上面一行和最左边一列遇到了障碍,则要把障碍的那一格和后面的格子初始值都设为0

时间复杂度:O(m * n)

空间复杂度:O(m * n)

  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值