Skip to content

Commit e42924f

Browse files
committed
Solution as on 05-03-2022 06:42 am
2 parents 8303bb2 + 98c376e commit e42924f

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

0740. Delete and Earn.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// 740.✅ Delete and Earn
2+
3+
class Solution
4+
{
5+
public:
6+
int deleteAndEarn(vector<int> &nums)
7+
{
8+
vector<int> freq(100001, 0);
9+
vector<int> t(100001, 0);
10+
11+
for (auto i : nums)
12+
++freq[i];
13+
14+
t[1] = freq[1];
15+
16+
for (int i = 2; i < 100001; ++i)
17+
{
18+
t[i] = max(t[i - 2] + i * freq[i], t[i - 1]);
19+
}
20+
21+
return t[10000];
22+
}
23+
};

0 commit comments

Comments
 (0)