Given an array nums, you can choose a value x and earn x points for each occurrence of x, but then you must delete every occurrence of x - 1 and x + 1. Return the maximum points you can earn. This is a choice DP problem that reduces to house-robber style selection over values.
nums = array of positive integers
maximum points you can earn
Example 1:
Input:
nums = [3,4,2]
Output:
6
Explanation:
Take 4 and delete 3 and 5; total points = 4 + 2 = 6.
Example 2:
Input:
nums = [2,2,3,3,3,4]
Output:
9
Explanation:
Take 3 three times for 9 points.