結果

問題 No.135 とりあえず1次元の問題
ユーザー YukimotoPG
提出日時 2019-02-14 14:08:50
言語 Java
(openjdk 23)
結果
AC  
実行時間 665 ms / 5,000 ms
コード長 513 bytes
コンパイル時間 2,193 ms
コンパイル使用メモリ 74,860 KB
実行使用メモリ 59,648 KB
最終ジャッジ日時 2024-09-13 11:23:47
合計ジャッジ時間 9,189 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		
		int n = sc.nextInt();
		if (n == 1) {
			System.out.println(0); return;
		}
		else {
			int[] ar = new int[n];
			for (int i=0; i<n; i++) ar[i] = sc.nextInt();
			Arrays.sort(ar);
			int min = Integer.MAX_VALUE;
			for (int i=1; i<n; i++) {
				if (ar[i]-ar[i-1] != 0) {
					min = Math.min(min, ar[i]-ar[i-1]);
				}
			}
			System.out.println(min==Integer.MAX_VALUE?0:min);
		}
		
	}
}
0