쉬운 문제라도 문제를 푸는 방법은 다양합니다.
더 명확하고 깔끔한 문제 해결 방법을 아신다면 자유롭게 말씀해주세요.
프로그래머스 120924 다음에 올 숫자
프로그래머스 저작권을 침해하지 않기 위해
문제 보시고 싶으시면 버튼을 눌러주세요.
답변 형식
common 배열을 받아 원소들의 관계를 등차수열 또는 등비수열로 판단한다.
등비 또는 등차의 크기를 구하여 마지막 원소 다음에 나올 숫자를 찾는다.
풀이 조건
최소 3개 이상의 원소가 나오기 때문에
– 1항과 2항
– 2항과 3항의 관계를
확인하면 됩니다.
배열의 크기가 999까지 가능하지만
종항의 다음 항이 int 범위 내에 있기 때문에 문제를 풀 때 형 크기에 대한 부담은 없습니다.
JAVA 정답
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;
}
}
JAVA 정답 해설
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;
}
}
JAVA 간결한 정답
class Solution {
public int solution(int[] common) {
if(common[1]-common[0] == common[2]-common[1])
return common[common.length–1]+(common[1] – common[0]);
else return common[common.length–1]*(common[1]/common[0]);
}
}
JAVA 삼항연산자
class Solution {
public int solution(int[] common) {
return common[1]-common[0] == common[2]-common[1] ?
common[common.length–1]+(common[1] – common[0]) :
common[common.length–1]*(common[1]/common[0]);
}
}
Python3 정답
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])
Python3 정답 해설
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])
# 등비수열이라면 마지막 항에 등비를 곱해서 제출한다.


Hmm, cái phần mô tả về sự đa dạng game này hay đấy. Nhìn chung thì ổn, nhưng mấy cái từ khóa liên quan đến c1688 app download nên được nhấn mạnh hơn cho người mới tìm hiểu. Cần rõ ràng hơn chút!
This place feels like a friendly neighborhood spot rather than a cold corporate site. The welcome package was exactly as advertised and I really liked how transparent the wagering requirements are. Customer chats are warm and genuinely helpful. I keep finding new promotions that actually fit my budget. mygcup5
Finally found a platform that actually delivers on its promises. The game variety is impressive and I had a great experience with the support team. Highly recommend krmegawins
I love how monthlymovie keeps their content updated. It is my go-to place for catching up on the latest releases without any hassle.
The winning streaks here are insane! I had a great run last night and the withdrawal was lightning fast. phww777 is the real deal.
Really impressed with the bonuses they offer for new players. It feels like they actually care about the user experience. Cheers to vn88tt
[1002]Tragamonedas: Login Oficial | Descarga la APK y Bonos de Bienvenida,Disfruta de las mejores tragamonedas con depósitos rápidos vía SPEI y ruletas online. Aprovecha los bonos de bienvenida y comienza a jugar hoy mismo. visit: tragamonedas
Quick access and no fuss. I love that I can jump straight into my favorite games without any annoying glitches. Very reliable platform. 291jililogin
[6021]superbet login করুন | বিকাশ দিয়ে ক্যাসিনো ডিপোজিট ও স্লট গেম,superbet login করুন এবং লাইভ ডিলার ক্যাসিনো গেম উপভোগ করুন। সহজেই superbet app download করে অনলাইন স্লট গেম নিয়ম জানুন ও খেলা শুরু করুন। visit: superbet
[1210]888sport লগইন এবং অ্যাপ ডাউনলোড | বিকাশ ক্যাসিনো ডিপোজিট,888sport লগইন করুন এবং অ্যাপ ডাউনলোড করে অনলাইন স্লট গেম খেলার নিয়ম জানুন। বিকাশ দিয়ে ক্যাসিনো ডিপোজিট করে আজই গেম খেলা শুরু করুন। visit: 888sport