leetcode 062 Unique Paths
来源:互联网 发布:知乎 毕业一年后 编辑:程序博客网 时间:2024/05/22 12:23
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.
Subscribe to see which companies asked this question
// class Solution {// public:// int uniquePaths(int m, int n) {// vector<vector<int> > matrix(100, vector<int>(100, 1));// //matrix[i][j] = matrix[i][j-1]+matrix[i-1][j]// for(int i = 1; i < n; i++) {// for(int j = 1; j < m; j++) {// matrix[i][j] = matrix[i][j-1]+matrix[i-1][j];// }// }// return matrix[n-1][m-1];// }// }class Solution {public:int uniquePaths(int m, int n) {if(m > n) return uniquePaths(n, m);vector<int> cur(m,1);//matrix[i][j] = matrix[i][j-1]+matrix[i-1][j]for(int j=1; j < n; j++) {for(int i=1; i < m; i++) {cur[i] += cur[i-1];}}return cur[m-1];}}
0 0
- LeetCode 062 Unique Paths
- LeetCode 062 Unique Paths
- LeetCode 062 Unique Paths
- leetcode 062 Unique Paths
- LeetCode 062 Unique Paths
- LeetCode: Unique Paths II [062]
- leetcode Unique Paths && Unique Paths
- Leetcode-Unique Paths&Unique PathsII
- leetcode 062 —— Unique Paths
- leetcode解题方案--062--Unique Paths
- [LeetCode] Unique Paths and Unique Paths II
- leetcode--Unique Paths && Unique Paths ii
- leetcode--Unique Paths && Unique Paths ii
- 【Leetcode】【python】Unique Paths/Unique Paths II
- LeetCode: Unique Paths
- LeetCode: Unique Paths II
- [Leetcode] Unique Paths
- [Leetcode] Unique Paths II
- Android活动被回收了的处理方式
- Codeforces 667C Reberland Linguistics (DP)
- 面试之路(16)-归并排序详解(MergeSort)递归和非递归实现
- MySQL 下 ROW_NUMBER / DENSE_RANK / RANK 的实现
- 两位数乘一位数
- leetcode 062 Unique Paths
- jsp页面中插入css样式的三种方法总结
- 练习
- poj 1007 DNA Sorting
- 图片无损压缩工具
- 三位数乘一位数
- IIS的安装和牛腩发布
- leetcode 063 Unique Paths II
- 单例模式例子