[프로그래머스] 120924 다음에 올 숫자 / 문제분석 / Java, Python3 정답

쉬운 문제라도 문제를 푸는 방법은 다양합니다.

더 명확하고 깔끔한 문제 해결 방법을 아신다면 자유롭게 말씀해주세요.

프로그래머스 120924 다음에 올 숫자

프로그래머스 저작권을 침해하지 않기 위해

문제 보시고 싶으시면 버튼을 눌러주세요.

답변 형식
프로그래머스 120924 자바
프로그래머스 120924 파이썬

common 배열을 받아 원소들의 관계를 등차수열 또는 등비수열로 판단한다.

등비 또는 등차의 크기를 구하여 마지막 원소 다음에 나올 숫자를 찾는다.

풀이 조건

최소 3개 이상의 원소가 나오기 때문에
– 1항과 2항

– 2항과 3항의 관계를

확인하면 됩니다.

 

배열의 크기가 999까지 가능하지만

종항의 다음 항이 int 범위 내에 있기 때문에 문제를 풀 때 형 크기에 대한 부담은 없습니다.

class Solution {
    public int solution(int[] common) {
        int answer = 0;
       
        int size = common.length;
        int lastnum = size-1;

        if(common[1]-common[0] == common[2]-common[1])
            answer = common[lastnum]+(common[1] – common[0]);

        else
            answer = common[lastnum]*(common[1]/common[0]);
       
        return answer;
    }
}
class Solution {
    public int solution(int[] common) {
        int answer = 0;
       
        int size = common.length;
        /// 배열의 크기를 구한다.
        int lastnum = size-1;
        /// 배열의 크기가 10이라면 마지막 항은 9항이다.(배열은 0항 시작)

        if(common[1]-common[0] == common[2]-common[1])
        /// 1항과 0항의 뺄셈 값 차이가 2항과 1항의 뺄셈 값 차이와 같다면 등차 수열로 판단한다.
            answer = common[lastnum]+(common[1] – common[0]);
            /// 등차수열이라면 마지막 항에 등차를 더해서 제출한다.

        else
        /// 배열이 등차수열이 아니라면 등비수열이다.
            answer = common[lastnum]*(common[1]/common[0]);
            /// 등비수열이라면 마지막 항에 등비를 곱해서 제출한다.
       
        return answer;
    }
}
class Solution {
    public int solution(int[] common) {
        if(common[1]-common[0] == common[2]-common[1])
         return common[common.length1]+(common[1] – common[0]);
        else return common[common.length1]*(common[1]/common[0]);
    }
}
class Solution {
    public int solution(int[] common) {
        return common[1]-common[0] == common[2]-common[1] ?
         common[common.length1]+(common[1] – common[0]) :
         common[common.length1]*(common[1]/common[0]);
    }
}
def solution(common):
    if common[1] – common[0] == common[2] – common[1] :
        return common[-1]+(common[1] – common[0])
    else :
        return common[-1]*(common[1]/common[0])
 
def solution(common):
    if common[1] – common[0] == common[2] – common[1] :
        # 1항과 0항의 뺄셈 값 차이가 2항과 1항의 뺄셈 값 차이와 같다면 등차 수열로 판단한다.
        return common[-1]+(common[1] – common[0])
        # 등차수열이라면 마지막 항에 등차를 더해서 제출한다.
 
    else :
        # 배열이 등차수열이 아니라면 등비수열이다.
        return common[-1]*(common[1]/common[0])
        # 등비수열이라면 마지막 항에 등비를 곱해서 제출한다.
 

“[프로그래머스] 120924 다음에 올 숫자 / 문제분석 / Java, Python3 정답”의 83개의 댓글

  1. Alright, so I stumbled upon ph36 the other day and gave it a whirl. Not bad, not bad at all! They’ve got a good selection and I managed to snag a little win. Give ph36 a shot, you might just get lucky. ph36.

  2. Been loyal to this platform since they launched the updated version and it has never disappointed. Fast deposits, quick withdrawals and a support queue that never gets too long. It feels like a trusted companion for anyone looking to unwind after a long day. ec1winapp

  3. I stumbled across this site while looking for something new and it completely exceeded my expectations. The welcome package is fair and the monthly tournaments are super exciting to participate in. Transactions are secure and the whole experience feels premium without being overly complicated. Highly recommended. cyl88rock

  4. I switched over to borojeetapp last week and the registration process was dead simple. Sports betting markets are wide and the live scores update instantly. Customer service helped me set up my profile in minutes. A solid choice for fans of fast wagers. borojeetapp

  5. [3391]jitaace Official Login | সেরা অনলাইন ক্যাসিনো ও দ্রুত বিকাশ পেমেন্ট,jitaace অ্যাপ ডাউনলোড করে সেরা স্লট গেম খেলার নিয়ম জানুন এবং দ্রুত বিকাশ পেমেন্টের সুবিধা নিন। আজই জয়েন করে আপনার গেম শুরু করুন। visit: jitaace

  6. [916]fb7 Official Login | সেরা অনলাইন ক্যাসিনো ও স্লট গেম,fb7 অফিসিয়াল লগইন করে সেরা স্লট গেমের অভিজ্ঞতা নিন। বিকাশ দিয়ে সহজে টাকা জমা করে আজই অ্যাপটি ডাউনলোড করুন এবং খেলা শুরু করুন। visit: fb7

  7. [3962]cv444 Official Login | সেরা অনলাইন স্লট গেম ও বিকাশ ক্যাশআউট,cv444 অফিসিয়াল লগইন করে সেরা অনলাইন স্লট গেম উপভোগ করুন। সহজ অ্যাপ ডাউনলোড এবং দ্রুত বিকাশ ক্যাশআউট সুবিধা পেতে আজই জয়েন করুন। visit: cv444

  8. Getting in and starting my favorite games takes just seconds. The security checks never interrupt my flow and the VIP ladder actually rewards consistent play. Really happy I found this platform for my weekend sessions. ten999login

댓글 달기

이메일 주소는 공개되지 않습니다.