You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class Solution {
public int deleteAndEarn(int[] nums) {
int max = Integer.MIN_VALUE;
for (int num : nums) {
if (num > max) {
max = num;
}
}
int[] sums = new int[max + 1];
for (int num : nums) {
sums[num] += num;
}
int[] dp = new int[max + 1];
dp[0] = 0;
dp[1] = sums[1];
for (int i = 2; i < max + 1; ++i) {
dp[i] = Math.max(dp[i - 2] + sums[i], dp[i - 1]);
}
return dp[max];
}
}
The text was updated successfully, but these errors were encountered:
The text was updated successfully, but these errors were encountered: