LeetCode Unique Paths
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?
class Solution { public: int uniquePaths(int m, int n) { vector<int> vec; vec.clear(); vec.push_back(1); if(m==1 || n==1) return 1; for(int i=1;i<m+n-2;i++) { vec.push_back(1); int j = vec.size()-1; while(j>=1) { vec[j] += vec[j-1]; j--; } } return vec[m-1]; } };
哼哼,挡板法,数学求解·······