Skip to content

Commit d05da6c

Browse files
committed
Time: 8 ms (62.02%), Space: 11.5 MB (26.69%) - LeetHub
1 parent 9a2d8d3 commit d05da6c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

delete-and-earn/delete-and-earn.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public:
3+
int deleteAndEarn(vector<int>& nums) {
4+
int n = 10002;
5+
vector<int> dp(n, 0);
6+
7+
for(auto x: nums)
8+
dp[x] += x;
9+
10+
for(int i = 2; i < n; i++){
11+
dp[i] = max(dp[i - 1], dp[i - 2] + dp[i]);
12+
}
13+
14+
return dp[n - 1];
15+
}
16+
};

0 commit comments

Comments
 (0)