알고리즘 풀이/Codility

Codility - Triangle (Sorting)

배게 2019. 12. 13. 04:46
728x90

N개수 10만개 보고 sorting 하는 것을 두려워하지 말자.. 


할거 다 해보고 도저히 모르겠을 때 해답보기, 


오버플로우를 대비해서 이항시켜주기


1
2
3
4
5
6
7
8
9
10
11
12
13
14
    public int solution(int[] A) {
        // write your code in Java SE 8
        if(A.length<=2return 0;
        
        Arrays.sort(A);
        
        // for(int a : A ) System.out.println(a);
        
        for(int i=A.length-1; i>=2; i--){
            if(A[i-1]>A[i-2]-A[i] && A[i-2]>A[i]-A[i-1&& A[i]>A[i-1]-A[i-2]) return 1;
            
        }
        return 0;
    }
cs


※ 알고보니 저 트라이앵글 식 중에 마지막 식만 만족해도 앞에 2개식도 만족하는 구도인 것을 알게됨