Question d’entretien chez Bloomberg

Find the smallest two values in an array

Réponses aux questions d'entretien

Utilisateur anonyme

15 juin 2016

private static void smallestTwoValues(int[] a) { int one = a[0] = a[1] ? a[0] : a[1]; for(int i = 2; i < a.length; i++) { if(a[i] < one) { two = one; one = a[i]; } } System.out.println(one); System.out.println(two); }

Utilisateur anonyme

13 mars 2015

Iterate through it and find the smallest two