2024/10/21 灵茶题单 不定长滑动窗口
This commit is contained in:
parent
95f3ae0c49
commit
8ad071fec0
|
@ -0,0 +1,32 @@
|
||||||
|
package com.cool.ling_cha_mount.sliding_windows;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created with IntelliJ IDEA.
|
||||||
|
*
|
||||||
|
* @Author: Cool
|
||||||
|
* @Date: 2024/10/21/14:51
|
||||||
|
* @Description: 1695. 删除子数组的最大得分
|
||||||
|
* Score 1529
|
||||||
|
*/
|
||||||
|
public class Num1695 {
|
||||||
|
public int maximumUniqueSubarray(int[] nums) {
|
||||||
|
int res = 0;
|
||||||
|
int sum = 0;
|
||||||
|
int[] arr = new int[10001];
|
||||||
|
int left = 0;
|
||||||
|
for (int i = 0; i < nums.length; i++) {
|
||||||
|
if (++arr[nums[i]] > 1) {
|
||||||
|
res = Math.max(res, sum);
|
||||||
|
while (true) {
|
||||||
|
sum -= nums[left];
|
||||||
|
--arr[nums[left]];
|
||||||
|
if (nums[left++] == nums[i]) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sum += nums[i];
|
||||||
|
}
|
||||||
|
return Math.max(res, sum);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue