Created
February 22, 2015 10:25
-
-
Save jordanterry/a164b8607ee4054ba80b to your computer and use it in GitHub Desktop.
This is a solution that worked.
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; | |
public class Solution { | |
public int solution(int[] A) { | |
Arrays.sort(A); | |
int l = A.length; | |
int result = A[l - 1] * A[l - 2] * A[l - 3]; | |
if(A[0] * A[1] > 0 && A[0] < 0) { | |
int altResult = A[0] * A[1] * A[l - 1]; | |
if(altResult > result) return altResult; | |
} | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment