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
Given an arraynumsof integers, you can perform operations on the array. In each operation, you pick anynums[i]and delete it to earnnums[i]points. After, you must delete every element equal tonums[i] - 1ornums[i] + 1. You start with 0 points. Return the maximum number of points y...
Given an arraynumsof integers, you can perform operations on the array. 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...
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 天,感谢阅读至此的你 欢迎点赞、收藏鼓励支持小满...
链接https://leetcode.com/problems/delete-and-earn/submissions/ 题目大意:有一堆数字构成的数组,删除某个数a会把数组内a-1和a+1都删除(如果存在),但不会删除其余的a, 删除后会得到和a相同的回报,问按照什么顺序删除回报最大 题解:很有意思的题目,有点类似house robbing ...
publicintdeleteAndEarn(int[]nums) { intmaxNum=-1; for(intnum:nums) {//求出原数组中的最大值 maxNum=Math.max(maxNum,num); } int[]sums=newint[maxNum+1];//根据最大值构建新数组 for(inti=0;i<nums.length;i++) { sums[nums[i]]+=nums[i]; ...
int deleteAndEarn(vector<int>& nums) { // [3,4,2] // dp[i] = max(dp[i-1], dp[i-2] + um[i] * i); unordered_map<int, int> count; int max_v = 0; for (auto x : nums) { count[x]++; max_v = max(max_v, x); ...
0740 Delete and Earn 57.4% Medium 0741 Cherry Pickup 36.3% Hard 0742 Closest Leaf in a Binary Tree 45.8% Medium 0743 Network Delay Time 51.4% Medium 0744 Find Smallest Letter Greater Than Target Go 44.6% Easy 0745 Prefix and Suffix Search Go 41.3% Hard 0746 Min Cost Climbing Stai...
740 Delete and Earn Medium Solution 741 Cherry Pickup Hard Solution 742 Closest Leaf in a Binary Tree Medium Solution 743 Network Delay Time Medium Solution 744 Find Smallest Letter Greater Than Target Easy Solution 745 Prefix and Suffix Search Hard Solution 746 Min Cost Climbing Stairs Easy Solut...
740 Delete and Earn Solution O(n) O(n) Medium 744 Find Smallest Letter Greater Than Target Solution O(logn) O(1) Easy 746 Min Cost Climbing Stairs Solution O(n) O(1) Easy 747 Largest Number Greater Than Twice of Others Solution O(n) O(1) Easy 748 Shortest Completing Word Sol...