尼采般地抒情

公告栏

此网站主题为本人手写主题, 主题待开源···

站点信息

文章总数目: 305
已运行时间: 1057
目录

尼采般地抒情

尼采般地抒情

公告栏

此网站主题为本人手写主题, 主题待开源···

站点信息

文章总数目: 305
已运行时间: 1057

代码还没有完成

  • 动态方程
  • 边界情况:对于目标位置arr[m-1][n-1]的周围被围绕这个边界情况遗漏了

/**

- @param {number[][]} obstacleGrid
- @return {number}
  \*/
  var uniquePathsWithObstacles = function(obstacleGrid) {
  let m = obstacleGrid.length
  let n = obstacleGrid[0].length

      if (m === 1 && n === 1) return obstacleGrid[0][0] === 0 ? 1 : 0
      if (m === 1) return obstacleGrid[0].includes(1) ? 0 : 1
      if (n === 1) {
          for (let i = 0; i<m; i++) {
              if (obstacleGrid[i][0] === 1) return 0
          }
      }
      if (obstacleGrid[0][0] === 1 || obstacleGrid[m-1][n-1] === 1) return 0

      for (let i = 0; i<m; i++) obstacleGrid[i][0] = obstacleGrid[i][0] === 0 ? 1 : 0
      for (let i = 0; i<n; i++) obstacleGrid[0][i] = obstacleGrid[0][i] === 0 ? 1 : 0

      for (let i = 1; i<m; i++) {
          for (let j = 1; j<n; j++) {
              obstacleGrid[i][j] === 1
                  ? obstacleGrid[i][j] = 0
                  : obstacleGrid[i][j] = obstacleGrid[i-1][j] + obstacleGrid[i][j-1]
          }
      }
      return obstacleGrid[m-1][n-1]

  };

评论区

Twikoo giscus