Skip to content

Commit 9078841

Browse files
committed
Runtime: 414 ms (Top 33.56%) | Memory: 88.6 MB (Top 56.51%)
1 parent 9e3b8da commit 9078841

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1+
// Runtime: 414 ms (Top 33.56%) | Memory: 88.6 MB (Top 56.51%)
12
var longestPalindromeSubseq = function(s) {
2-
const { length } = s;
3-
const dp = Array(length).fill('').map(() => Array(length).fill(0));
3+
const { length } = s;
4+
const dp = Array(length).fill('').map(() => Array(length).fill(0));
45

5-
for (let start = 0; start < length; start++) {
6-
const str = s[start];
7-
dp[start][start] = 1;
6+
for (let start = 0; start < length; start++) {
7+
const str = s[start];
8+
dp[start][start] = 1;
89

9-
for (let end = start - 1; end >= 0; end--) {
10-
dp[start][end] = str === s[end]
11-
? dp[start - 1][end + 1] + 2
12-
: Math.max(dp[start - 1][end], dp[start][end + 1])
13-
}
14-
}
15-
return dp[length - 1][0];
10+
for (let end = start - 1; end >= 0; end--) {
11+
dp[start][end] = str === s[end]
12+
? dp[start - 1][end + 1] + 2
13+
: Math.max(dp[start - 1][end], dp[start][end + 1])
14+
}
15+
}
16+
return dp[length - 1][0];
1617
};

0 commit comments

Comments
 (0)