第四题 离散化+滑动窗口,不知道写的对不对,有巨佬看看有问题没 public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int K = sc.nextInt(); int cnt = 0; int[] C = new int[N]; Map<Integer, Integer> map = new HashMap<>(); for (int i = 0; i < N; i++) { int t = sc.nextInt(); if (!map.containsKey(t)){ map.put(t, cnt++); } C[i] = map.get(t); } int[] count = new int[cnt]; int left=0, right=0, result=0, maxCount=0; while (right<C.length){ count[C[right]]++; maxCount = Math.max(maxCount, count[C[right]]); if (right-left+1-maxCount>K){ count[C[left]]--; left++; } right++; } System.out.println(maxCount); }
点赞 1

相关推荐

2025-11-13 20:16
已编辑
厦门理工学院 软件测试
专业嗎喽:硕佬,把学校背景放后面几段,学校背景双非还学院,让人看了就不想往下看。 把实习经历和个人奖项放前面,用数字化简述自己实习的成果和掌握的技能,比如负责项目一次通过率90%,曾4次发现项目潜在问题风险为公司减少损失等等
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务