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?
Problem solving idea One:
The Biginteger,java is implemented as follows:
Import Java.math.biginteger;public class Solution {public int uniquepaths (int m, int n) {if (n > m) {int temp = N;n = M ; m = temp;} Return Amn (M + n-2, n-1). Divide (factorial (n-1)). Intvalue (); static BigInteger Amn (int m, int n) {if (n = = 0) return biginteger.valueof (1), if (n = = 1) return biginteger.valueof (m); Elser Eturn Amn (m-1, n-1). Multiply (biginteger.valueof (M));} static BigInteger factorial (int n) {if (n = = 1 | | n = = 0) return biginteger.valueof (1); Elsereturn factorial (n-1). Multiply (Biginteger.valueof (n));}}
Java for Leetcode 062 Unique Paths