classSolution:""" @param obstacleGrid: An list of lists of integers @return: An integer """defuniquePathsWithObstacles(self,obstacleGrid):# write your code here# dp[i][j]: # of path at <i,j># dp[i][j] = max(dp[i-1][j],dp[i][j-1]) + 1row=len(obstacleGrid)col=len(obstacleGrid[0])dp=[[1]*(col+1)foriinrange(row+1)]foriinrange(1,row+1):forjinrange(1,col+1):#dp[0][0]ifi==1andj==1:dp[i][j]=1-obstacleGrid[i-1][j-1]#dp[1][j]elifi==1:ifobstacleGrid[i-1][j-1]==1:dp[i][j]=0else:dp[i][j]=dp[i][j-1]#dp[i][1]elifj==1:ifobstacleGrid[i-1][j-1]==1:dp[i][j]=0else:dp[i][j]=dp[i-1][j]#dp[i][j]else:ifobstacleGrid[i-1][j-1]==1:dp[i][j]=0else:dp[i][j]=dp[i-1][j]+dp[i][j-1]returndp[i][j]