File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ leetcode 测试
10
10
11
11
##### 包含的内容如下
12
12
13
+ https://leetcode.cn/problems/unique-paths-ii
14
+
13
15
https://leetcode.cn/problems/rectangle-overlap/
14
16
15
17
https://leetcode.cn/problems/design-an-expression-tree-with-evaluate-function/
Original file line number Diff line number Diff line change
1
+ function uniquePathsWithObstacles ( obstacleGrid : number [ ] [ ] ) : number {
2
+ if ( obstacleGrid [ 0 ] [ 0 ] === 1 ) return 0 ;
3
+ const m = obstacleGrid . length ,
4
+ n = obstacleGrid [ 0 ] . length ;
5
+ if ( obstacleGrid [ m - 1 ] [ n - 1 ] === 1 ) return 0 ;
6
+
7
+ const f : number [ ] = Array ( n ) . fill ( 0 ) ;
8
+ f [ 0 ] = 1 ;
9
+ for ( let i = 0 ; i < m ; i ++ ) {
10
+ for ( let j = 0 ; j < n ; j ++ ) {
11
+ if ( obstacleGrid [ i ] [ j ] === 1 ) {
12
+ f [ j ] = 0 ;
13
+ } else if ( j >= 1 && obstacleGrid [ i ] [ j - 1 ] === 0 ) {
14
+ f [ j ] = f [ j ] + f [ j - 1 ] ;
15
+ }
16
+ }
17
+ }
18
+ return f [ f . length - 1 ] ;
19
+ }
20
+ export default uniquePathsWithObstacles ;
You can’t perform that action at this time.
0 commit comments