Leetcode Problem 740. Delete and Earn

740. Delete and Earn

Leetcode Solutions

Approach: Top-Down Dynamic Programming

  1. Create a hash table points to map numbers to their total points.
  2. Find the largest number in nums, maxNumber.
  3. Define a recursive function maxPoints(num) that uses memoization to store results.
  4. In maxPoints, check if num is in the memoization cache. If so, return the cached result.
  5. If num is not in the cache, compute maxPoints(num) using the recurrence relation.
  6. Store the computed result in the cache before returning it.
  7. Call maxPoints(maxNumber) to get the maximum points and return it.
UML Thumbnail

Approach: Bottom-Up Dynamic Programming

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...