Created
January 29, 2018 10:24
-
-
Save clarkdo/f6e958c2009ff588bc092cbe5c27e1ef to your computer and use it in GitHub Desktop.
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.*; | |
// you can write to stdout for debugging purposes, e.g. | |
// System.out.println("this is a debug message"); | |
class Solution { | |
public int solution(int[] A) { | |
Arrays.sort(A); | |
int length = A.length; | |
int P = A[length-3]; | |
int Q = A[length-2]; | |
int R = A[length-1]; | |
int max = P*Q*R; | |
if (length > 3) { | |
int negative = Q*R*A[0]; | |
if (max < negative) { | |
max = negative; | |
} | |
int positive = R*A[0]*A[1]; | |
if (max < positive) { | |
max = positive; | |
} | |
} | |
return max; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment