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 天,感谢阅读至此的你 欢迎点赞、收藏鼓励支持小满...
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...
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
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, ...
链接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]; ...
0734-Sentence-Similarity 0735-Asteroid-Collision 0736-Parse-Lisp-Expression 0737-Sentence-Similarity-II 0740-Delete-and-Earn/cpp-0740 CMakeLists.txt main.cpp main2.cpp old .gitignore qrcode.jpg readme.mdBreadcrumbs Play-Leetcode /0740-Delete-and-Earn /cpp-0740 / main...
740. Delete and Earn Given an array nums of integers, you can perform operations on the array. In each operation, you pick any nums[i] and delete it to earn nums[i] points. After, you must delete every element equal to nums[i] - 1 or nums[i] + 1....
每次操作中,选择任意一个nums[i] ,删除它并获得nums[i] 的点数。之后,你必须删除每个等于nums[i] - 1 或nums[i] + 1 的元素。 开始你拥有 0 个点数。返回你能通过这些操作获得的最大点数。 链接:https://leetcode-cn.com/problems/delete-and-earn ...
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