class Solution: def maximumSubarraySum(self, nums: List[int], k: int) -> int: # ans 维护所有长度为 k 且数字各不相同的子数组中,子数组和的最大值 ans: int = 0 # sum 维护当前滑动窗口 [l, r] 内的数字和 sum: int = 0 # num_to_cnt 表示滑动窗口 [l, r] 内每个数字的出现次数 nu...
You are given an array of positive integers nums and want to erase a subarray containing unique elements. The score you get by erasing the subarray is equal to the sum of its elements. Return the maximum score you can get by erasing exactly one subarray. An array b is called to be a ...
1)和maxSum( 2)两种情况; 当sum > 0 时, 有 maxSum(2) + (k-2)*sum. Java代码classSolution{publicintkConcatenationMaxSum(int[] arr,intk){if( arr.length ==0|| arr ==null)return0;if(k <3)return(int) (maxSum(arr, k)%(1e9+7));longsum =0;for(intnum:arr) sum += num;lon...
[LeetCode] 1695. Maximum Erasure Value You are given an array of positive integersnumsand want to erase a subarray containing unique elements. The score you get by erasing the subarray is equal to the sum of its elements. Returnthe maximum score you can get by erasing exactly one subarray....
classSolution{publiclongmaxMatrixSum(int[][]matrix){long sum=0;int counter=0;int min=Integer.MAX_VALUE;int n=matrix.length;for(int i=0;i<n;i++){for(int j=0;j<matrix[0].length;j++){if(matrix[i][j]<0)counter++;matrix[i][j]=Math.abs(matrix[i][j]);if(matrix[i][j]<min...
Return the maximum sub-array sum in the modified array. Note that the length of the sub-array can be 0 and its sum in that case is 0. As the answer can be very large, return the answer modulo 10^9 + 7. Example 1: Input: arr = [1,2], k = 3 ...
2178. 拆分成最多数目的正偶数之和 - 给你一个整数 finalSum 。请你将它拆分成若干个 互不相同 的正偶数之和,且拆分出来的正偶数数目 最多 。 * 比方说,给你 finalSum = 12 ,那么这些拆分是 符合要求 的(互不相同的正偶数且和为 finalSum):(2 + 10) ,(2 + 4 + 6)
LeetCode 325. Maximum Size Subarray Sum Equals k 若谷 追求卓越,成功就会在不经意间追上你 来自专栏 · 今日事 题目: Given an array nums and a target value k, find the maximum length of a subarray that sums to k. If there isn't one, return 0 instead. Note:The sum of the entire nums...
1691. 堆叠长方体的最大高度排序加最长递增子序列 本
Explanation: Because we can choose [1, -2, 0, 3] and drop -2, thus the subarray [1, 0, 3] becomes the maximum value. Example 2: Input: arr = [1,-2,-2,3] Output: 3 Explanation: We just choose [3] and it's the maximum sum. ...