Created
July 12, 2014 20:59
-
-
Save pranuthi9/b157a3e43224d8aad6da to your computer and use it in GitHub Desktop.
Codility - Lesson 4 - Triangle
This file contains 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
// you can also use imports, for example: | |
// import java.math.*; | |
// you can use System.out.println for debugging purposes, e.g. | |
// System.out.println("this is a debug message"); | |
import java.util.Arrays; | |
class Solution { | |
public int solution(int[] A) { | |
// write your code in Java SE 8 | |
int len = A.length; | |
Arrays.sort(A); | |
int res = 0; | |
int i = 0; | |
while (i <= len-3) { | |
res = isTriangle(A[i], A[i+1], A[i+2]); | |
if (res == 1) | |
break; | |
i++; | |
} | |
return res; | |
} | |
public int isTriangle(int a, int b, int c) { | |
if (a+b > c && b+c > a && c+a > b) { | |
return 1; | |
} | |
else return 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment