You are viewing a single comment's thread. Return to all comments →
Java Solution:
public class Solution {
static Scanner sc = new Scanner(System.in); public static void main(String[] args) { int n = sc.nextInt(); int v[] = new int[n]; int aux[] = new int[n-1]; for (int i = 0; i < n; i++) { v[i] = sc.nextInt(); } Arrays.sort(v); for(int i=0; i<n-1; i++){ aux[i] = Math.abs(v[i+1]-v[i]); } Arrays.sort(aux); for(int i=0; i<n-1; i++){ if(aux[0] == Math.abs(v[i+1]-v[i])) System.out.print(v[i] + " " + v[i+1]+ " "); } }
}
Seems like cookies are disabled on this browser, please enable them to open this website
Closest Numbers
You are viewing a single comment's thread. Return to all comments →
Java Solution:
public class Solution {
}