We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
给你一个正整数数组 nums ,请你从中删除一个含有 若干不同元素 的子数组。删除子数组的 得分 就是子数组各元素之 和 。
返回 只删除一个 子数组可获得的 最大得分 。
如果数组 b 是数组 a 的一个连续子序列,即如果它等于 a[l],a[l+1],...,a[r] ,那么它就是 a 的一个子数组。
输入:nums = [4,2,4,5,6] 输出:17 解释:最优子数组是 [2,4,5,6]
输入:nums = [5,2,1,2,5,2,1,2,5] 输出:8 解释:最优子数组是 [5,2,1] 或 [1,2,5]
来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/maximum-erasure-value 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
The text was updated successfully, but these errors were encountered:
题目直接明了,有连续子序列关键字,一看就是一道滑动窗口
func maximumUniqueSubarray(nums []int) int { var ret int i, j, l := 0, 0, len(nums) m := make(map[int]bool) var sum int for i < l && j < l { if m[nums[j]] { m[nums[i]] = false sum -= nums[i] i++ } else { sum += nums[j] m[nums[j]] = true j++ } ret = max(ret, sum) } return ret } func max(x, y int) int { if x > y { return x } return y }
Sorry, something went wrong.
No branches or pull requests
给你一个正整数数组 nums ,请你从中删除一个含有 若干不同元素 的子数组。删除子数组的 得分 就是子数组各元素之 和 。
返回 只删除一个 子数组可获得的 最大得分 。
如果数组 b 是数组 a 的一个连续子序列,即如果它等于 a[l],a[l+1],...,a[r] ,那么它就是 a 的一个子数组。
示例 1:
示例 2:
提示:
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/maximum-erasure-value
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
The text was updated successfully, but these errors were encountered: