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

    [JAVA 문제 풀이] 91. 다음에 올 숫자

    프로그래머스 (120924)
    Stupefyee's avatar
    Stupefyee
    Feb 18, 2025
    [JAVA 문제 풀이] 91. 다음에 올 숫자
    Contents
    내가 작성한 코드
    school.programmers.co.kr
    https://school.programmers.co.kr/learn/courses/30/lessons/120924
    notion image
     

    내가 작성한 코드

    class Solution { public int solution(int[] common) { int answer = common[common.length - 1]; // 가장 큰 수 // 두 수의 차를 구하기 위한 변수 >> 문제에서 배열의 길이는 3이상으로 명시됨됨 int num1 = common[1] - common[0]; int num2 = common[2] - common[1]; // 두 수가 같은 경우 >> 등차수열 if(num1 == num2) { answer += num1; } // 두 수가 다른 경우 >> 등비수열 if (num1 != num2) { answer *= common[2] / common[1]; } return answer; } }
     
    Share article
    Contents
    내가 작성한 코드

    stupefyee

    RSS·Powered by Inblog