Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
62. Unique Paths 不同路径
难度: Medium
刷题内容
一个机器人位于一个 m x n 网格的左上角 (起始点在下图中标记为“Start” )。
机器人每次只能向下或者向右移动一步。机器人试图达到网格的右下角(在下图中标记为“Finish”)。
问总共有多少条不同的路径?

例如,上图是一个7 x 3 的网格。有多少可能的路径?
说明:m 和 n 的值均不超过 100。
示例 1:
示例 2:
解题方案
例子中,m=7、n=3,也就是说,可以向右走6步(
m-1)和向下走2步(n-2);如果用符号
→表示向右走,符号↓表示向下走,那么这道题就变成了,(m-1)个→和(n-1)个↓有多少种排列组合方式,也就是最终自行实现阶乘计算函数——
factorial即可代码:
如果用每个格子上的值表示,当前格子到左上角格子的走法数量的话,那么右下角格子的值就是最终结果,样子如下
发现规律,每个格子的值等于
左侧格子值 + 上方格子值,所以用双层循环绘制表格,再去最后的值即可。