70. Climbing Stairs

202401211611
tags: #dp

var climbStairs = function(n) {
	const memo = new Map();
	
	const compute = (n) => {
		if (n <= 2) {
			return n;
		}
		if (memo.has(n)) {
			return memo.get(n);
		}
		const total = compute(n - 1) + compute(n - 2);
		memo.set(n, total);
		return total;
	}
	
	return compute(n);
};

Reference

https://leetcode.com/problems/climbing-stairs/