1695. Maximum Erasure Value Medium
1/**
2 * [1695] Maximum Erasure Value
3 *
4 * 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.
5 * Return the maximum score you can get by erasing exactly one subarray.
6 * An array b is called to be a <span class="tex-font-style-it">subarray</span> of a if it forms a contiguous subsequence of a, that is, if it is equal to a[l],a[l+1],...,a[r] for some (l,r).
7 *
8 * Example 1:
9 *
10 * Input: nums = [4,2,4,5,6]
11 * Output: 17
12 * Explanation: The optimal subarray here is [2,4,5,6].
13 *
14 * Example 2:
15 *
16 * Input: nums = [5,2,1,2,5,2,1,2,5]
17 * Output: 8
18 * Explanation: The optimal subarray here is [5,2,1] or [1,2,5].
19 *
20 *
21 * Constraints:
22 *
23 * 1 <= nums.length <= 10^5
24 * 1 <= nums[i] <= 10^4
25 *
26 */
27pub struct Solution {}
28
29// problem: https://leetcode.com/problems/maximum-erasure-value/
30// discuss: https://leetcode.com/problems/maximum-erasure-value/discuss/?currentPage=1&orderBy=most_votes&query=
31
32// submission codes start here
33
34impl Solution {
35 pub fn maximum_unique_subarray(nums: Vec<i32>) -> i32 {
36 0
37 }
38}
39
40// submission codes end
41
42#[cfg(test)]
43mod tests {
44 use super::*;
45
46 #[test]
47 fn test_1695() {
48 }
49}
50
Back
© 2025 bowen.ge All Rights Reserved.