【LeetCode】C# 62、Unique Paths
来源:互联网 发布:淘宝红线绿线流量图 编辑:程序博客网 时间:2024/05/18 04:21
A robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below).
The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked ‘Finish’ in the diagram below).
How many possible unique paths are there?
Above is a 3 x 7 grid. How many possible unique paths are there?
Note: m and n will be at most 100.
判断机器人有几种路线到达终点。在只能往下往右走的情况下。
思路:有个规律,map[i][j] = map[i-1][j]+map[i][j-1]
每一格的路线数等于他上面和左边格子的路线和。所以通过设置第一行第一列为一,之后遍历即可得到最后一个格子,就是终点的路线数。
public class Solution { public int UniquePaths(int m, int n) { int[][] map = new int[m][]; for(int i = 0; i<m;i++){ map[i] = new int[n]; map[i][0] = 1; } for(int j= 0;j<n;j++){ map[0][j]=1; } for(int i = 1;i<m;i++){ for(int j = 1;j<n;j++){ map[i][j] = map[i-1][j]+map[i][j-1]; } } return map[m-1][n-1]; }}
阅读全文
0 0
- 【LeetCode】C# 62、Unique Paths
- [leetcode 62] Unique Paths
- LeetCode(62): Unique Paths
- [LeetCode 62]Unique Paths
- leetcode || 62、Unique Paths
- Unique Paths - LeetCode 62
- leetcode-62 Unique Paths
- Leetcode[62]-Unique Paths
- leetcode 62:Unique Paths
- Leetcode #62 Unique Paths
- leetcode 62: Unique Paths
- Leetcode#62||Unique Paths
- LeetCode 62: Unique Paths
- 【leetcode】【62】Unique Paths
- leetcode #62 Unique Paths
- leetcode 62:Unique Paths
- 【LEETCODE】62-Unique Paths
- Leetcode 62: Unique Paths
- Java访问者模式以及在访问者模式中使用反射
- 文章标题 实验四:用可重用的链表模块来实现命令行菜单小程序V2.5
- A Deep Convolutional Neural Network for segmenting and classifying epithelial and stromal regions
- Qt去掉窗口标题栏实现移动缩放
- 急什么,我们又不赶时间
- 【LeetCode】C# 62、Unique Paths
- 金融科技&大数据产品推荐:天眼查——人人都能用的商业调查工具
- 阿里云天池医疗AI大赛第一季迎来最后决赛,医疗AI面临哪些机遇与阻碍
- 【案例】融360:智能金融系统建设最佳实践案例
- 【POJ 3107 】Godfather 【树的重心】
- TMUX CAFFE等小技巧
- 静态成员变量成员函数
- max-points-on-a-line java code
- c++11的新特性---基于范围的for循环