MCPcopy Create free account
hub / github.com/HuberTRoy/leetCode / uniquePaths

Method uniquePaths

DP/UniquePath.py:54–74  ·  view source on GitHub ↗

:type m: int :type n: int :rtype: int

(self, m, n)

Source from the content-addressed store, hash-verified

52
53class Solution(object):
54 def uniquePaths(self, m, n):
55 """
56 :type m: int
57 :type n: int
58 :rtype: int
59 """
60
61 _map = [[0 for _ in range(m)] for _ in range(n)]
62 # _map[0][0] = 1
63
64 for i in range(n):
65 for j in range(m):
66 x = _map[i-1][j] if i - 1 >= 0 else 0
67 y = _map[i][j-1] if j - 1 >= 0 else 0
68
69 if x + y == 0:
70 _map[i][j] = 1
71 else:
72 _map[i][j] = x + y
73
74 return _map[n-1][m-1]
75

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected