1
var numTrees = function (n) {
2
// Create 'sol' array to store the solution...
3
var sol = [1, 1];
4
// Run a loop from 2 to n...
5
for (let i = 2; i <= n; i++) {
6
sol[i] = 0;
7
// Within the above loop, run a nested loop from 1 to i...
8
for (let j = 1; j <= i; j++) {
9
// Update the i-th position of the array by adding the multiplication of the respective index...
10
sol[i] += sol[i - j] * sol[j - 1];
11
}
12
}
13
// Return the value of the nth index of the array to get the solution...
14
return sol[n];
15
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0