Delete and Earn

You are given an integer array nums. In one step you can pick any element x, earn x points, and then delete every occurrence of x-1 and x+1 from the array. You may perform this operation any number of times. Return the maximum number of points you can earn across all steps.

Examples
Input: [3,4,2]
Output: 6
Hints

Delete and Earn

You are given an integer array nums. In one step you can pick any element x, earn x points, and then delete every occurrence of x-1 and x+1 from the array. You may perform this operation any number of times. Return the maximum number of points you can earn across all steps.