yukicoder No.135 とりあえず1次元の問題

Problem

No.135 とりあえず1次元の問題 - yukicoder

Code

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        int N = Integer.parseInt(reader.readLine());
        String[] inputs = reader.readLine().split(" ");
        long[] points = new long[N];
        for (int i = 0; i < N; i++) {
            points[i] = Long.parseLong(inputs[i]);
        }
        Arrays.sort(points);
        long minDistance = Long.MAX_VALUE;
        boolean found = false;
        for (int i = 1; i < N; i++) {
            if(points[i]  != points[i-1] ) {
                found = true;
                minDistance = Math.min(minDistance, Math.abs(points[i] - points[i-1]));
            }
        }

        if (found) {
            System.out.println(minDistance);
        } else {
            System.out.println(0);
        }

    }