[Python] short dp solution, explained
This is a classical dynamic programming problem. Let dp[i][j] be the number of paths to reach coordinate (i, j).  Then first of all we check if we can reach (0,
This is a classical **dynamic programming** problem. Let `dp[i][j]` be the number of paths to reach coordinate `(i, j)`.  Then first of all we check if we can reach `(0, 0)` coordinate. Then for each cell we check two neighbours: one above and one to the left and add this number of ways to answer. In the end we return `dp[-1][-1]`\n\n#### Complexity\nTime complexity is `O(mn)`, because we have `mn` states and two transactions from one to another. Space complexity is the same.\n\n\n#### Code\n```python\nclass Solution:\n    def uniquePathsWithObstacles(self, M):\n        m, n = len(M), len(M[0])\n        dp = [[0] * n for _ in range(m)]\n        dp[0][0] = int(M[0][0] == 0)\n        for i, j in product(range(m), range(n)):\n            if M[i][j] == 1: continue\n            if i > 0: dp[i][j] += dp[i-1][j]\n            if j > 0: dp[i][j] += dp[i][j-1]\n                \n        return dp[-1][-1]\n```\n\nIf you have any questions, feel free to ask. If you like solution and explanations, please **Upvote!**
['Dynamic Programming']