最长全1串

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int cnt = 0 , tem=k;
        int max = 0;
        int a[] = new int[n];
        LinkedList list = new LinkedList<>();
        for(int i=0;i0){
                cnt++;
                tem--;
                list.add(i);
            }
            else if(tem==0){
                max=Math.max(max,cnt);
                list.add(i);
                int start = list.poll();
                cnt = i-start;
            }
        }
        max=Math.max(max,cnt);
        System.out.println(max);
    }
}

你可能感兴趣的:(最长全1串)