| Conditions | 6 |
| Paths | 5 |
| Total Lines | 19 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 26 | public static function uniquePathsWithObstacles2(array $grids): int |
||
| 27 | { |
||
| 28 | [$m, $n] = [count($grids), count($grids[0])]; |
||
| 29 | if ($m <= 0 || $n <= 0) { |
||
| 30 | return 0; |
||
| 31 | } |
||
| 32 | $dp = array_fill(0, $n, 0); |
||
| 33 | $dp[0] = 1; |
||
| 34 | foreach ($grids as $grid) { |
||
| 35 | for ($j = 1; $j < $n; $j++) { |
||
| 36 | if ($grid[$j] === 1) { |
||
| 37 | $dp[$j] = 0; |
||
| 38 | } else { |
||
| 39 | $dp[$j] += $dp[$j - 1]; |
||
| 40 | } |
||
| 41 | } |
||
| 42 | } |
||
| 43 | |||
| 44 | return $dp[$n - 1]; |
||
| 45 | } |
||
| 47 |