爱奇艺笔试

//爱奇艺笔试0913
// 三数之和
public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    List<Integer> list = new ArrayList<>();
    Set<String> set = new HashSet<>();
    while(sc.hasNext()) {
        int temp = sc.nextInt();
        list.add(temp);

    }
    int n = list.size();
    Collections.sort(list);
    for(int i=0; i < n; i++) {
        for(int j=i+1; j < n; j++) {
            for(int k=j+1; k < n; k++) {
                int a = list.get(i), b = list.get(j), c = list.get(k);
                if(a+b+c == 0) {
                    String str = a + " " + b +" " + c;
                    if(!set.contains(str)) {
                        System.out.println(str);
                        set.add(str);
                    }
                }
            }
        }
    }
}



public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    List<Integer> list = new ArrayList<>();
    while(sc.hasNext()) {
        int temp = sc.nextInt();
        list.add(temp);
    }
    int n = list.size();
    int count = 1, num = list.get(0);
    for(int i=1; i < n; i++) {
        int t = list.get(i);
        if(t == num) count++;
        else {
            if(count > 1) count --;
            else {
                count = 1;
                num = t;
            }
        }
    }
    System.out.println(num);
}

public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    char[] s = sc.next().toCharArray();
    int n = s.length;
    int[] cnt = new int[256];
    int res = 0;
    for(int i=0, j=0; j < n; j++) {
        int t = s[j] - 'a';
        cnt[t]++;
        if(cnt[t] > 1) {
            cnt[t] = 1;
            i ++;
            //System.out.println("i "+ j);
        }
        res = Math.max(res, j-i+1);
    }
    System.out.println(res);
}

原文地址:https://www.cnblogs.com/lixyuan/p/13663469.html