Skip to content

Commit e5cf9b4

Browse files
committed
[level 0] Title: 마지막 두 원소, Time: 0.03 ms, Memory: 90.3 MB -BaekjoonHub
1 parent 8dd1298 commit e5cf9b4

2 files changed

Lines changed: 95 additions & 0 deletions

File tree

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# [level 0] 마지막 두 원소 - 181927
2+
3+
[문제 링크](https://school.programmers.co.kr/learn/courses/30/lessons/181927)
4+
5+
### 성능 요약
6+
7+
메모리: 90.3 MB, 시간: 0.03 ms
8+
9+
### 구분
10+
11+
코딩테스트 연습 > 코딩 기초 트레이닝
12+
13+
### 채점결과
14+
15+
정확성: 100.0<br/>합계: 100.0 / 100.0
16+
17+
### 제출 일자
18+
19+
2026년 03월 23일 13:41:24
20+
21+
### 문제 설명
22+
23+
<p>정수 리스트 <code>num_list</code>가 주어질 때, 마지막 원소가 그전 원소보다 크면 마지막 원소에서 그전 원소를 뺀 값을 마지막 원소가 그전 원소보다 크지 않다면 마지막 원소를 두 배한 값을 추가하여 return하도록 solution 함수를 완성해주세요.</p>
24+
25+
<hr>
26+
27+
<h5>제한사항</h5>
28+
29+
<ul>
30+
<li>2 ≤ <code>num_list</code>의 길이 ≤ 10</li>
31+
<li>1 ≤ <code>num_list</code>의 원소 ≤ 9</li>
32+
</ul>
33+
34+
<hr>
35+
36+
<h5>입출력 예</h5>
37+
<table class="table">
38+
<thead><tr>
39+
<th>num_list</th>
40+
<th>result</th>
41+
</tr>
42+
</thead>
43+
<tbody><tr>
44+
<td>[2, 1, 6]</td>
45+
<td>[2, 1, 6, 5]</td>
46+
</tr>
47+
<tr>
48+
<td>[5, 2, 1, 7, 5]</td>
49+
<td>[5, 2, 1, 7, 5, 10]</td>
50+
</tr>
51+
</tbody>
52+
</table>
53+
<hr>
54+
55+
<h5>입출력 예 설명</h5>
56+
57+
<p>입출력 예 #1</p>
58+
59+
<ul>
60+
<li>마지막 원소인 6이 그전 원소인 1보다 크기 때문에 6 - 1인 5를 추가해 return합니다.</li>
61+
</ul>
62+
63+
<p>입출력 예 #2</p>
64+
65+
<ul>
66+
<li>마지막 원소인 5가 그전 원소인 7보다 크지 않기 때문에 5의 두 배인 10을 추가해 return합니다.</li>
67+
</ul>
68+
69+
70+
> 출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/challenges
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution {
2+
public int[] solution(int[] num_list) {
3+
4+
int length = num_list.length;
5+
int tmp;
6+
7+
int[] answer = new int[length + 1];
8+
9+
for(int i=0; i<length; i++){
10+
answer[i] = num_list[i];
11+
}
12+
13+
if(num_list[length-1] > num_list[length-2]){
14+
tmp = num_list[length-1] - num_list[length-2];
15+
}
16+
else{
17+
tmp = num_list[length-1]*2;
18+
}
19+
20+
answer[length] = tmp;
21+
22+
23+
return answer;
24+
}
25+
}

0 commit comments

Comments
 (0)