結果

問題 No.8009 異なる数字の最大の範囲(勉強会用)
ユーザー tenten
提出日時 2021-02-12 10:30:23
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 709 bytes
コンパイル時間 2,310 ms
コンパイル使用メモリ 75,288 KB
実行使用メモリ 65,892 KB
最終ジャッジ日時 2024-06-12 22:37:37
合計ジャッジ時間 10,155 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 6 WA * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        HashSet<Integer> exist = new HashSet<>();
        int left = 0;
        int max = 0;
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
            if (exist.contains(arr[i])) {
                while (arr[left] != arr[i]) {
                    exist.remove(arr[left]);
                    left++;
                }
            } else {
                exist.add(arr[i]);
                max = Math.max(max, i - left + 1);
            }
        }
        System.out.println(max);
    }
}
0