# [leetcode] 62. 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?

public class Solution {
public int uniquePaths(int m, int n) {
int result = 0;
if(m ==0 || m ==0){
return 0;
}

int[][] nums = new int[m][n];

for(int i = 0; i < n; i++){
nums[0][i] = 1;
}
for(int i = 0; i < m; i++){
nums[i][0] = 1;
}

for(int i = 1; i < m;i++){
for(int j = 1; j < n; j++){
nums[i][j] = nums[i][j-1]+ nums[i-1][j];
}
}

result = nums[m-1][n-1];
return result;
}
}

public class Solution {
public int uniquePaths(int m, int n) {
long result = 1;
if (m == 1 || n == 1) {
return (int)result;
}

int x = m > n ? m : n;
int y = m < n ? m : n;
int chu = 1;

int zonghe = m+n-2;
for(int i =0; i < y-1; i++){
result = result * (zonghe-i);

}
for(int i =0; i < y-1; i++){
chu = chu * (i+1);
}
return (int)(result/chu);
}
}

• 本文已收录于以下专栏：

举报原因： 您举报文章：[leetcode] 62. Unique Paths 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)