From 266e67f8bebfe8358912b19df55cf4d30635863f Mon Sep 17 00:00:00 2001 From: Cool <747682928@qq.com> Date: Sun, 13 Oct 2024 20:00:07 +0800 Subject: [PATCH] =?UTF-8?q?2024/10/13=20=E7=81=B5=E8=8C=B6=E9=A2=98?= =?UTF-8?q?=E5=8D=95=20=E6=BB=91=E5=8A=A8=E7=AA=97=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sliding_windows/Num2653.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/main/java/com/cool/ling_cha_mount/sliding_windows/Num2653.java 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; + } + + +}