結果

問題 No.135 とりあえず1次元の問題
ユーザー Tsukasa_TypeTsukasa_Type
提出日時 2018-02-09 19:51:33
言語 Java
(openjdk 23)
結果
AC  
実行時間 678 ms / 5,000 ms
コード長 535 bytes
コンパイル時間 2,026 ms
コンパイル使用メモリ 74,796 KB
実行使用メモリ 60,180 KB
最終ジャッジ日時 2024-10-08 04:06:17
合計ジャッジ時間 8,732 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public 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);}
		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;
			boolean F = false;
			for (int i=0; i<n-1; i++) {
				int temp = Math.abs(ar[i+1]-ar[i]);
				if (temp!=0) {min = Math.min(min,temp); F = true;}
			}
			System.out.println(F==true?min:0);
		}
	}
}
0