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
855cb035
authored
Oct 05, 2020
by
李楚霏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
week7
parent
9812fab4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
0 deletions
+26
-0
70works/week7/daily/unique_paths_ii.js
+26
-0
No files found.
70works/week7/daily/unique_paths_ii.js
0 → 100644
View file @
855cb035
/**
* @param {string} text1
* @param {string} text2
* @return {number}
*/
var
longestCommonSubsequence
=
function
(
text1
,
text2
)
{
// let t1 = text1.split('');
// let t2 = text2.split('');
let
row
=
text1
.
length
;
let
col
=
text2
.
length
;
if
(
row
===
0
||
col
===
0
)
return
0
;
//dp代表text1 前i个字符与 text2前i个字符的公共子串长度
let
dp
=
Array
.
apply
(
null
,
{
length
:
row
+
1
}).
map
(()
=>
Array
.
apply
(
null
,
{
length
:
col
+
1
}).
map
(()
=>
0
));
for
(
let
i
=
1
;
i
<=
row
;
i
++
)
{
for
(
let
j
=
1
;
j
<=
col
;
j
++
)
{
if
(
text1
[
i
-
1
]
===
text2
[
j
-
1
])
{
dp
[
i
][
j
]
=
dp
[
i
-
1
][
j
-
1
]
+
1
;
}
else
{
dp
[
i
][
j
]
=
Math
.
max
(
dp
[
i
-
1
][
j
],
dp
[
i
][
j
-
1
]);
}
}
}
return
dp
[
row
][
col
];
};
\ 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