max(dp[i - 2] + sum); } // 最后 dp[max_num] 就是能获得最大分数 dp[max_num as usize] as i32 } } 题目链接: Delete and Earn : leetcode.com/problems/d 删除并获得点数: leetcode-cn.com/problem LeetCode 日更第 50 天,感谢阅读至此的你 欢迎点赞、收藏鼓励支持小满...
In each operation, you pick anynums[i]and delete it to earnnums[i]points. After, you must delete everyelement equal tonums[i] - 1ornums[i] + 1. You start with 0 points. Return the maximum number of points you can earn by applying such operations. Example 1: Input: nums = [3, ...
classSolution {publicintdeleteAndEarn(int[] nums) {if(nums ==null|| nums.length == 0)return0;int[] freq =newint[10001];for(intnum : nums) freq[num]++;intdp1 = freq[0] * 0;intdp2 = Math.max(dp1, freq[1]*1);intdp =dp2;for(inti = 2; i < 10001; i++) { dp= Math.m...
Can you solve this real interview question? Delete and Earn - You are given an integer array nums. You want to maximize the number of points you get by performing the following operation any number of times: * Pick any nums[i] and delete it to earn num
链接https://leetcode.com/problems/delete-and-earn/submissions/ 题目大意:有一堆数字构成的数组,删除某个数a会把数组内a-1和a+1都删除(如果存在),但不会删除其余的a, 删除后会得到和a相同的回报,问按照什么顺序删除回报最大 题解:很有意思的题目,有点类似house robbing ...
File metadata and controls Code Blame 18 lines (18 loc) · 441 Bytes Raw class Solution { public: int deleteAndEarn(vector<int>& nums) { int maxnum=0; int trans[10001]={0}; for(int i:nums){ trans[i]+=i; maxnum=max(maxnum,i); } int dp[maxnum+1]; dp[0]=trans[0]; ...
class Solution { public int deleteAndEarn(int[] nums) { int[] count = new int[10001]; for (int x: nums) count[x]++; int avoid = 0, using = 0, prev = -1; for (int k = 0; k <= 10000; ++k) if (count[k] > 0) { ...
(maxNum) class Solution { public: int deleteAndEarn(vector<int>& nums) { vector<int> scores(10001, 0); int maxNum = 0; for(int num: nums){ scores[num] += num; maxNum = max(num, maxNum); } vector<int> dp(maxNum + 1, 0); dp[1] = scores[1]...
Leetcode 740. Delete and Earn 文章作者:Tyan 博客:noahsnail.com | CSDN | 简书 1. Description 2. Solution Reference https://leetcode.com/problems/delete-and-earn/description/ 【leetcode系列】【py3】【中等】四数之和 = []nums.sort() for index1inrange(0, num_len - 3): if index1 > ...
Can you solve this real interview question? Delete and Earn - You are given an integer array nums. You want to maximize the number of points you get by performing the following operation any number of times: * Pick any nums[i] and delete it to earn num