Simple Java O(1) space solution
For cell i,j we just need to sum left cell + top cell.\nIf any of them is obstacle, then we say it\'s 0, otherwise take it\'s value.\n\n\n    public int uniqueP
For cell i,j we just need to sum left cell + top cell.\nIf any of them is obstacle, then we say it\'s 0, otherwise take it\'s value.\n\n```\n    public int uniquePathsWithObstacles(int[][] grid) {\n        int n = grid.length, m = grid[0].length;\n        if (grid[0][0] == 1 || grid[n - 1][m - 1] == 1) return 0;\n        grid[0][0] = 1;\n        for(int i = 0; i < n; i++) {\n            for(int j = 0; j < m; j++) {\n                if (i == 0 && j == 0) continue;\n                if (grid[i][j] == 1) {\n                    grid[i][j] = 0;\n                } else {\n                    int top = i == 0 ? 0 : grid[i - 1][j];\n                    int left = j == 0 ? 0 : grid[i][j - 1];\n                    grid[i][j] = top + left;        \n                }\n            }\n        }\n        return grid[n - 1][m - 1];\n    }\n```
['Dynamic Programming']