C++ solution beats 100%


  • 0
    H
    class Solution {
    public:
        int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) {
            if (obstacleGrid[0][0]) return 0;
            
            int m = obstacleGrid.size();
            int n = obstacleGrid[0].size();
            vector<vector<int>> nPaths(m, vector<int>(n));
            
            nPaths[0][0] = 1;
            for (int s = 1; s <= m+n; ++s) {
                for (int r = max(0, s - n + 1); r <= s && r < m; ++r) {
                    int c = s - r;
                    if (c >= n)
                        continue;
                    if (c < 0)
                        break;
                        
                    nPaths[r][c] = obstacleGrid[r][c] ?
                        0 : (r > 0 ? nPaths[r-1][c] : 0) + (c > 0 ? nPaths[r][c-1] : 0);
                }
            }
            
            return nPaths[m-1][n-1];
        }
    };
    

  • 0

    Where did you get the "beats 100%" from? Is the runtime distribution including that message not disabled for you? (It should be disabled and it is for me)


  • 0
    H
    This post is deleted!

  • 0
    H

    @StefanPochmann I got to have the time distribution when I submitted the solution. But now it's gone...


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.