9 lines Clean JAVA solution


  • 0
    L
    public class Solution {
        public int uniquePathsWithObstacles(int[][] obstacleGrid) {
            int[][] dp = new int[obstacleGrid.length+1][obstacleGrid[0].length+1];
            dp[1][0] = 1;
            for(int i=1; i<=obstacleGrid.length; i++){
                for(int j=1; j<=obstacleGrid[0].length; j++){
                    if(obstacleGrid[i-1][j-1]==1) dp[i][j] = 0;
                    else dp[i][j] = dp[i-1][j] + dp[i][j-1];
                }
            }
            return dp[obstacleGrid.length][obstacleGrid[0].length];
        }
    }
    

Log in to reply
 

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