結果

問題 No.135 とりあえず1次元の問題
ユーザー rf141
提出日時 2015-08-10 04:00:15
言語 Java
(openjdk 23)
結果
AC  
実行時間 611 ms / 5,000 ms
コード長 630 bytes
コンパイル時間 3,590 ms
コンパイル使用メモリ 76,452 KB
実行使用メモリ 49,888 KB
最終ジャッジ日時 2025-01-03 07:25:38
合計ジャッジ時間 10,703 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
public class liner{
	public static void main(String... args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		if(n==1){
			System.out.println(0);
			return;
		}
		int[] point = new int[n];
		for(int i = 0; i < n; i++){
			point[i] = scan.nextInt();
		}
		Arrays.sort(point);
		System.out.println(result(point,n));
	}
	public static int result(int[] point,int n){
		int min = 1000001;
		for(int i = 0; i < n-1; i++){
			if(point[i]!=point[i+1]){
				if(point[i+1]-point[i] < min && point[i+1]-point[i] > 0){
					min = point[i+1]-point[i];
				}
			}
		}
		return (min==1000001)?0:min;
	}
}
0