Last active
January 4, 2016 01:09
-
-
Save edwardbeckett/149e2ce348cc8efb90e6 to your computer and use it in GitHub Desktop.
Find second largest value in an int[]...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
import java.util.Random; | |
/** | |
* @author Edward Beckett <[email protected]> | |
* @since 1/3/2016 | |
*/ | |
public class ArraySecondMax { | |
private static int[] nums = new Random().ints(10000, 0, 10000).toArray(); | |
private static int secondMax (int... array) { | |
Arrays.stream(array).sorted().distinct(); | |
return array.length-1; | |
} | |
public static void main(String[] args) { | |
System.out.println(secondMax(nums)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment