Skip to content

Commit 5b50138

Browse files
committed
[level 0] Title: 가까운 수, Time: 0.03 ms, Memory: 61.4 MB -BaekjoonHub
1 parent b8f783c commit 5b50138

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

프로그래머스/0/120890. 가까운 수/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# [level 0] 가까운 수 - 120890
22

3-
[문제 링크](https://school.programmers.co.kr/learn/courses/30/lessons/120890)
3+
[문제 링크](https://school.programmers.co.kr/learn/courses/30/lessons/120890?language=java)
44

55
### 성능 요약
66

7-
메모리: 10.2 MB, 시간: 0.00 ms
7+
메모리: 61.4 MB, 시간: 0.03 ms
88

99
### 구분
1010

@@ -16,7 +16,7 @@
1616

1717
### 제출 일자
1818

19-
2024년 05월 24일 11:59:31
19+
2026년 05월 25일 12:48:58
2020

2121
### 문제 설명
2222

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public int solution(int[] array, int n) {
3+
int answer = array[0];
4+
int minDiff = Math.abs(array[0] - n);
5+
6+
for (int i: array){
7+
int diff = Math.abs(i-n);
8+
9+
if (diff < minDiff){
10+
minDiff = diff;
11+
answer = i;
12+
}
13+
else if (minDiff == diff && i < answer){
14+
answer = i;
15+
}
16+
}
17+
return answer;
18+
}
19+
}

0 commit comments

Comments
 (0)