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 is there?
Above is a 3 x 7 grid. How many possible unique paths is there?
Typical motion rules, note the boundary conditions can be.
1 classSolution {2 Public:3 intUniquepaths (intMintN) {4 int* Path =New int[m*n];5 for(inti =0; I! = m; i++){6 for(intj =0; J! = N; J + +){7 if(i = =0){8 if(J = =0)9Path[i*n + j] =1;Ten Else OnePath[i*n + j] = Path[i*n + J-1]; A } - Else{ - if(J = =0) thePath[i*n + j] = path[(i-1) *n +j]; - Else -Path[i*n + j] = Path[i*n + J-1] + path[(i-1) *n +j]; - } + } - } + returnPath[m*n-1]; A } at};
[Leetcode] Unique Paths