Created
January 29, 2018 09:45
-
-
Save clarkdo/e76944e6050f66f386a8473a9dbd2c80 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.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; | |
} | |
} |
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.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