// you can also use imports, for example:
import java.util.*;

// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");

class Solution {
    
    public int solution(int[] A) {
        // write your code in Java SE 8
        
        if (A.length < 3) {
            return 0;
        }
        Arrays.sort(A);
        
        int start = 0;
        while (start < A.length) {
            if (A[start] > 0) {
                break;
            }
            start++;
        }
        
        if (start >= A.length) {
            return 0;
        }
        
        int result = 0;
        for (int i = 0; i < A.length-1; i++) {
            for (int j = (i+1); j < A.length-1; j++) {
                
                if ((long)A[i] + (long)A[j] > (long)A[j+1]) {
                    result = 1;
                    break;
                }
            }
            if (result == 1) {
                break;
            }
        }
        
        return result;
    }
}

'알고리즘' 카테고리의 다른 글

[codility] lesson5 - PassingCars  (0) 2020.08.14
[codility] lesson4 - FrogRiverOne  (0) 2020.08.13
[codility] lesson3 - FrogJmp  (0) 2020.08.12
[codility] lesson2 - CyclicRotation  (0) 2020.08.12
[codility] Lesson1 - Binary Gap  (0) 2020.08.12

+ Recent posts