inblog logo
|
stupefyee
    알고리즘문제풀기

    [JAVA 문제 풀이] 74. 삼각형의 완성조건 (2)

    프로그래머스 (120868)
    Stupefyee's avatar
    Stupefyee
    Feb 06, 2025
    [JAVA 문제 풀이] 74. 삼각형의 완성조건 (2)
    Contents
    내가 작성한 코드다른 사람의 코드
    school.programmers.co.kr
    https://school.programmers.co.kr/learn/courses/30/lessons/120868
    notion image
    💡
    • 삼각형 변의 조건
    notion image

    내가 작성한 코드

    💡
    class Solution { public int solution(int[] sides) { int side1 = sides[0]; int side2 = sides[1]; // 두수의 합 - 두수의 차 절대값 - 1 return (side1 + side2) - Math.abs(side1 - side2) - 1; } }
    • -1을 붙이는 이유? 배열 중 가장 큰 변의 길이 == c 가 되는 경우는 없음 >> -1 해주기

    다른 사람의 코드

    💡
    class Solution { public int solution(int[] sides) { int answer = 0; int min = Math.min(sides[0], sides[1]); answer += min * 2 - 1; return answer; } }
     
    Share article
    Contents
    내가 작성한 코드다른 사람의 코드

    stupefyee

    RSS·Powered by Inblog