Skip to content

Instantly share code, notes, and snippets.

@stephen-maina
Created April 14, 2015 08:25
Show Gist options
  • Save stephen-maina/07ae26798c5094756fdb to your computer and use it in GitHub Desktop.
Save stephen-maina/07ae26798c5094756fdb to your computer and use it in GitHub Desktop.
MaxProductOfThree lesson 4
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