LeetCode 62. Unique Paths
来源:互联网 发布:java测试需要会什么 编辑:程序博客网 时间:2024/06/16 20:07
问题描述:
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?
算法思路:如果机器人要走到 [ i , j ] 位置,他只有两种方法(1)从[ i , j-1 ] 往下走(2)从[ i-1 , j ] 往右走,这样就变成了一个递归问题。使用数组来解,每个位置记录着机器人从start point到达该点的方法
算法:
class Solution {public: int uniquePaths(int m, int n) { int arr[100][100];arr[0][0] = 1;for(int i=0;i<m;i++)for (int j = 0; j < n; j++) { if (i==0&&j==0) continue;if (i == 0)arr[i][j] = arr[i][j - 1];else if (j == 0)arr[i][j] = arr[i - 1][j];elsearr[i][j] = arr[i - 1][j] + arr[i][j - 1];}return arr[m-1][n-1]; }};
阅读全文
0 0
- [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
- 62. Unique Paths LeetCode
- [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中对象的创建和销毁
- linux 查询目录下包含关键字的所有文件
- FastJson的一般使用
- picasso使用
- spring boot 两个war包同时在tomcat中部署后启动报错
- LeetCode 62. Unique Paths
- Linux下常用的C/C++开源Socket库
- Android中传入一个角度一张图片 返回旋转后的Bitmap.
- ADAS概述
- 欢迎使用CSDN-markdown编辑器
- 算法导论中的图搜索算法范例
- 【memcache缓存专题(1)】memcache的介绍与应用场景
- windows生成redis服务【Redis · 2】
- jsp中forward跳转和response跳转的区别