We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ff5be5b commit 142c98cCopy full SHA for 142c98c
Dynamic-Programming/LongestPalindromicSubsequence.js
@@ -7,13 +7,19 @@
7
*/
8
9
export const longestPalindromeSubsequence = function (s) {
10
+ if (typeof s !== 'string') {
11
+ throw new TypeError('Input must be a string')
12
+ }
13
+
14
const n = s.length
15
- const dp = new Array(n)
- .fill(0)
- .map((item) => new Array(n).fill(0).map((item) => 0))
16
+ if (n === 0) {
17
+ return 0
18
19
20
+ const dp = new Array(n).fill(0).map(() => new Array(n).fill(0))
21
- // fill predefined for single character
22
+ // single character palindromes
23
for (let i = 0; i < n; i++) {
24
dp[i][i] = 1
25
}
0 commit comments