[Codility Lessons] Triangle(16/n)
[Lesson6] Sorting
Triangle : Determine whether a triangle can be built from a given set of edges.
Java Solution
Task Score : 93
Correctness : 90 Performance : 100
import java.util.*;
class Solution {
public int solution(int[] A) {
Arrays.sort(A);
for(int i = 0; i < A.length-2; i++){
if(A[i] + A[i+1] > A[i+2]){
return 1;
}
}
return 0;
}
}
Task Score : 100
import java.util.*;
class Solution {
public int solution(int[] A) {
Arrays.sort(A);
for(int i = 0; i < A.length-2; i++){
if((long)A[i] + (long)A[i+1] > A[i+2]){
return 1;
}
}
return 0;
}
}
PHP Solution
function solution($A) {
sort($A);
for($i = 0; $i < count($A)-2; $i++){
if($A[$i]+$A[$i+1] > $A[$i+2]){
return 1;
}
}
return 0;
}