Skip to content

Instantly share code, notes, and snippets.

@clarkdo
Created January 29, 2018 09:45
Show Gist options
  • Save clarkdo/e76944e6050f66f386a8473a9dbd2c80 to your computer and use it in GitHub Desktop.
Save clarkdo/e76944e6050f66f386a8473a9dbd2c80 to your computer and use it in GitHub Desktop.
import java.util.Arrays;
class Solution {
public int solution(int[] A) {
if (A == null || A.length < 3) return 0;
int max = Integer.MAX_VALUE;
Arrays.sort(A);
long last = A[A.length-1];
for (int i = 0; i < A.length-2; i++) {
long P = A[i];
if (P <= 0) continue;
if (P > max) break;
for (int j = i+1; j < A.length-1; j++) {
long Q = A[j];
if (Q > max) break;
if (P + last <= Q) {
break;
}
for (int k = j+1; k < A.length; k++) {
long R = A[k];
if (R > max) break;
if (P + Q > R && P + R > Q && R + Q > P) {
return 1;
}
}
}
}
return 0;
}
}
import java.util.Arrays;
class Solution {
public int solution(int[] A) {
if (A == null || A.length < 3) return 0;
Arrays.sort(A);
for (int i = 0; i < A.length-2; i++) {
long P = A[i];
if (P <= 0) continue;
if (P > Integer.MAX_VALUE) break;
long Q = A[i+1];
long R = A[i+2];
if (P + Q > R) {
return 1;
}
}
return 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment