Skip to content

Latest commit

 

History

History
19 lines (19 loc) · 550 Bytes

leetcode62_多除py2没问题py3会有问题.md

File metadata and controls

19 lines (19 loc) · 550 Bytes
class Solution:
    def uniquePaths(self, m: int, n: int) -> int:
        from functools import reduce
        if m==0:
            return n
        if n == 0:
            return m
        m, n = max(m,n), min([m,n])
        m = m + n - 2
        n = n - 1
        la,lo,lo2 = map(lambda l:reduce(lambda a,b:a*b, l), [
        range(1,m+1) if m > 1 else [1,1],
        range(1,n+1) if n > 1 else [1,1],
        range(1,m-n+1) if m-n > 1 else [1,1],
        ])
        return int(la/(lo*lo2))
        # 注意,多次除法会有问题