Skip to content

Instantly share code, notes, and snippets.

@jordanterry
Created February 22, 2015 10:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jordanterry/a164b8607ee4054ba80b to your computer and use it in GitHub Desktop.
Save jordanterry/a164b8607ee4054ba80b to your computer and use it in GitHub Desktop.
This is a solution that worked.
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