Created
April 14, 2015 08:25
-
-
Save stephen-maina/07ae26798c5094756fdb to your computer and use it in GitHub Desktop.
MaxProductOfThree lesson 4
This file contains hidden or 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.stream.IntStream; | |
import java.lang.Math; | |
class Solution { | |
public int solution(int[] A) { | |
// write your code in Java SE 8 | |
int [] sorted=IntStream.of(A).sorted().toArray(); | |
return Math.max(sorted[0]*sorted[1]*sorted[sorted.length-1],sorted[sorted.length-1]*sorted[sorted.length-2]*sorted[sorted.length-3]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment