結果

問題 No.135 とりあえず1次元の問題
ユーザー tenten
提出日時 2020-11-10 16:21:32
言語 Java
(openjdk 23)
結果
AC  
実行時間 738 ms / 5,000 ms
コード長 611 bytes
コンパイル時間 2,239 ms
コンパイル使用メモリ 75,428 KB
実行使用メモリ 57,180 KB
最終ジャッジ日時 2024-07-22 17:33:56
合計ジャッジ時間 8,964 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        TreeSet<Integer> set = new TreeSet<>();
        for (int i = 0; i < n; i++) {
            set.add(sc.nextInt());
        }
        if (set.size() <= 1) {
            System.out.println(0);
            return;
        }
        int prev = Integer.MIN_VALUE / 10;
        int min = Integer.MAX_VALUE;
        for (int x : set) {
            min = Math.min(min, x - prev);
            prev = x;
        }
        System.out.println(min);
    }
}
0