leetcode Unique Paths

来源:互联网 发布:电池校准软件 编辑:程序博客网 时间:2024/05/17 05:17

题目链接

思路:
这个题目就是求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());    }}
0 0
原创粉丝点击