Skip to content

An improvement on Ficbonacci function using DP #81

Description

@duongtq

// My code just improves a little
// Feel free to ask me questions

function dp_ficbo(n)
{
var val = [];
for ( let i = 0; i <= n; i++)
{
val[i] = 0;
}

	if ( n == 1 || n == 2)
	{
		return 1;
	}
	else
	{
		val[1] = 1;
		val[2] = 2;

		for ( let i = 3; i <= n; i++ )
		{
			val[i] = val[i - 1] + val[i - 2];
		}
	}

	return val[n - 1];
}

console.log(dp_ficbo(20));

Metadata

Metadata

Assignees

No one assigned

    Labels

    on holdBeing discussed by the maintainers

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions