leetcode Unique Paths

题目链接

思路:
这个题目就是求c(m+n-2,n-1)。。也是组合数学里面非降路径的概念

import java.math.BigInteger;
public class Solution {
    public int uniquePaths(int m, int n) {
         BigInteger result=new BigInteger("0");
        BigInteger up=new BigInteger("1");
        BigInteger down=new BigInteger("1");


        for(int i=m;i<m+n-1;i++)
        {
            up=up.multiply(new BigInteger(Integer.toString(i)));

        }

        for(int i=1;i<=n-1;i++)
        {
            down=down.multiply(new BigInteger(Integer.toString(i)));
        }
        result=up.divide(down);
        return Integer.valueOf(result.toString());
    }
}

你可能感兴趣的:(leetcode Unique Paths)