Path Sum II @ LeetCode (Python)
Unique Paths II @ LeetCode (Python)

Unique Paths @ LeetCode (Python)

kitt posted @ 2014年3月12日 23:52 in LeetCode , 2399 阅读

m行n列, 需要往下走m-1步, 往右走n-1步, 也就是求C(m-1+n-1, n-1)或C(m-1+n-1, m-1)。

class Solution:
    # @return an integer
    def uniquePaths(self, m, n):
        N = m - 1 + n - 1
        K = min(m, n) - 1
        # calculate C(N, K)
        res = 1
        for i in xrange(K):
            res = res * (N - i) / (i + 1)
        return res

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter