diff --git a/src/main/java/com/cool/ling_cha_mount/sliding_windows/Num2653.java b/src/main/java/com/cool/ling_cha_mount/sliding_windows/Num2653.java new file mode 100644 index 0000000..f183d29 --- /dev/null +++ b/src/main/java/com/cool/ling_cha_mount/sliding_windows/Num2653.java @@ -0,0 +1,37 @@ +package com.cool.ling_cha_mount.sliding_windows; + +/** + * Created with IntelliJ IDEA. + * + * @Author: Cool + * @Date: 2024/10/13/19:59 + * @Description: 2653. 滑动子数组的美丽值 + * Hard 2 + * Level 5 + * Score 1786 + */ +public class Num2653 { + + public int[] getSubarrayBeauty(int[] nums, int k, int x) { + int[] count = new int[101]; + int[] res = new int[nums.length - k + 1]; + for (int i = 0; i < k - 1; i++) { + count[nums[i] + 50]++; + } + for (int i = k - 1; i < nums.length; i++) { + count[nums[i] + 50]++; + int val = x; + for (int j = 0; j < 50; j++) { + val -= count[j]; + if (val <= 0) { + res[i - k + 1] = j - 50; + break; + } + } + count[nums[i - k + 1] + 50]--; + } + return res; + } + + +}