2024/10/23 灵茶题单 不定长滑动窗口
This commit is contained in:
parent
dd0ceaf000
commit
d97230a73b
src/main/java/com/cool/ling_cha_mount/sliding_windows
|
@ -0,0 +1,28 @@
|
|||
package com.cool.ling_cha_mount.sliding_windows;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Created with IntelliJ IDEA.
|
||||
*
|
||||
* @Author: Cool
|
||||
* @Date: 2024/10/23/23:48
|
||||
* @Description: 2779. 数组的最大美丽值
|
||||
* Score 1638
|
||||
*/
|
||||
public class Num2779 {
|
||||
public int maximumBeauty(int[] nums, int k) {
|
||||
Arrays.sort(nums);
|
||||
int left=0;
|
||||
int res=0;
|
||||
for(int i=0;i<nums.length;i++){
|
||||
if((nums[i]-2*k)>nums[left]){
|
||||
res=Math.max(res,i-left);
|
||||
while(nums[i]-2*k>nums[++left]){
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return Math.max(res,nums.length-left);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue