LeetCode: Jump Game II Solution
1/**2 * @param {number[]} nums3 * @return {number}4 */5var jump = function (nums) {6 const recursion = (i, memo = {}) => {7 if (memo[i] !== undefined) {8 return memo[i]9 }1011 if (i >= nums.length - 1) {12 return 013 }1415 let minSteps = Infinity16 for (let step = 1; step <= nums[i]; step++) {17 minSteps = Math.min(minSteps, 1 + recursion(i + step, memo))18 }1920 return (memo[i] = minSteps)21 }2223 return recursion(0)24}
Comments
Loading comments...
Tags
leetcode
array
greedy
recursion
dynamic programming
Apply and earn a $2,500 bonus once you're hired on your first job!
Clients from the Fortune 500 to Silicon Valley startups
Choose your own rate, get paid on time
From hourly, part-time, to full-time positions
Flexible remote working environment
A lot of open JavaScript jobs!!
Fact corner: Referred talent are 5x more likely to pass the Toptal screening process than the average applicant.
Still hesitate? Read HoningJS author's guide on dealing with Toptal interview process.
Next Post
Previous Post
LeetCode: Non Decreasing Array
May 5, 2021