第四题 离散化+滑动窗口,不知道写的对不对,有巨佬看看有问题没 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

相关推荐

萧索X:写篮球联赛干嘛,陪老板打篮球吗。还有实习经历要写自己所在岗位具体完成什么工作,自己的任务具体完成了什么需求,给公司带来了哪些量化增长
点赞 评论 收藏
分享
程序员牛肉:继续沉淀吧同学,你这就是纯纯的流水线产品。 差不多的学历+两个烂大街项目。自身学历又不行,现在找啥实习呢。有点太浮躁了。多花点心思搞搞ai,开源和八股。这比你这段时间捣鼓一段小厂实习要好得多;
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务