Advertisement
Guest User

Untitled

a guest
Sep 28th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3. import java.math.*;
  4.  
  5. /**
  6. * Auto-generated code below aims at helping you parse
  7. * the standard input according to the problem statement.
  8. **/
  9. class Solution {
  10.  
  11. public static void main(String args[]) {
  12. Scanner in = new Scanner(System.in);
  13. int N = in.nextInt();
  14. Vector<Integer> list = new Vector<Integer>();
  15. for (int i = 0; i < N; i++) {
  16. list.add(in.nextInt());
  17. }
  18. Collections.sort(list);
  19. int min = list.elementAt(1) - list.elementAt(0);
  20. for(int i = 2;i<list.size();i++){
  21. int diff = list.elementAt(i) - list.elementAt(i-1);
  22. if(diff < min){
  23. min = diff;
  24. }
  25. }
  26.  
  27. // Write an action using System.out.println()
  28. // To debug: System.err.println("Debug messages...");
  29. System.err.println(list);
  30. System.out.println("" + min);
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement