Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
李楚霏
/
leetCode_Solution_Record
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
2ba644c0
authored
Oct 03, 2020
by
李楚霏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
week6-unique_paths_ii
parent
415cc2ae
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
0 deletions
+31
-0
70works/week6/unique_paths_ii.js
+31
-0
No files found.
70works/week6/unique_paths_ii.js
0 → 100644
View file @
2ba644c0
/**
* @param {number[][]} obstacleGrid
* @return {number}
*/
/**
* @param {number[][]} obstacleGrid
* @return {number}
*/
var
uniquePathsWithObstacles
=
function
(
obstacleGrid
)
{
if
(
obstacleGrid
.
length
<
0
)
return
0
;
if
(
obstacleGrid
[
0
][
0
]
===
1
)
return
0
;
let
row
=
obstacleGrid
.
length
;
let
col
=
obstacleGrid
[
0
].
length
;
const
dp
=
Array
.
apply
(
null
,
{
length
:
row
+
1
}).
map
(
()
=>
Array
.
apply
(
null
,
{
length
:
col
+
1
}).
map
(()
=>
0
));
dp
[
1
][
1
]
=
1
;
//遍历的length得用dp的长度,而不能用obstacleGrid的长度
for
(
let
i
=
1
;
i
<
dp
.
length
;
i
++
)
{
for
(
let
j
=
1
;
j
<
dp
[
i
].
length
;
j
++
)
{
if
(
obstacleGrid
[
i
-
1
][
j
-
1
]
===
1
||
i
===
1
&&
j
===
1
)
continue
;
dp
[
i
][
j
]
=
dp
[
i
-
1
][
j
]
+
dp
[
i
][
j
-
1
];
}
}
console
.
error
(
dp
[
row
][
col
]);
return
dp
[
row
][
col
];
};
let
obsobstacleGrid
=
[[
0
,
0
,
0
],[
0
,
1
,
0
],[
0
,
0
,
0
]];
uniquePathsWithObstacles
(
obsobstacleGrid
);
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment