結果
問題 |
No.8009 異なる数字の最大の範囲(勉強会用)
|
ユーザー |
![]() |
提出日時 | 2021-02-12 12:08:39 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 625 ms / 5,000 ms |
コード長 | 733 bytes |
コンパイル時間 | 2,799 ms |
コンパイル使用メモリ | 75,316 KB |
実行使用メモリ | 55,132 KB |
最終ジャッジ日時 | 2024-11-20 15:03:00 |
合計ジャッジ時間 | 10,420 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 |
ソースコード
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++; } left++; } else { exist.add(arr[i]); max = Math.max(max, i - left + 1); } } System.out.println(max); } }