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