Skip to content

Instantly share code, notes, and snippets.

@clarkdo
Created January 29, 2018 10:24
Show Gist options
  • Save clarkdo/f6e958c2009ff588bc092cbe5c27e1ef to your computer and use it in GitHub Desktop.
Save clarkdo/f6e958c2009ff588bc092cbe5c27e1ef to your computer and use it in GitHub Desktop.
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