삼각형의 완성조건 (2)

han.user();·2023년 4월 6일
0

프로그래머스

목록 보기
44/87
post-thumbnail

import java.util.Arrays;

class Solution {
    public int solution(int[] sides) {
        int count = 0;

        int[] three = Arrays.copyOf(sides, 3);

        for (int i = 1; i <= three[0] + three[1]; i++) {
            three = Arrays.copyOf(sides, 3);
            three[2] = i;
            Arrays.sort(three); // 변의 길이를 오름차순으로 정렬
            int maxLength = three[2];
            int twoLength = three[0] + three[1];
            if (twoLength > maxLength) {
                count++;
            }
        }
        return count;
    }
}
profile
I'm still hungry.

0개의 댓글