Skip to content

Commit 2abc6bb

Browse files
committed
[level 1] Title: 체육복, Time: 0.04 ms, Memory: 73.7 MB -BaekjoonHub
1 parent 6e83489 commit 2abc6bb

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed

프로그래머스/1/42862. 체육복/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
### 성능 요약
66

7-
메모리: 82.4 MB, 시간: 0.03 ms
7+
메모리: 73.7 MB, 시간: 0.04 ms
88

99
### 구분
1010

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

1717
### 제출 일자
1818

19-
2025년 01월 26일 23:53:43
19+
2025년 09월 05일 13:06:12
2020

2121
### 문제 설명
2222

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,34 @@
1+
import java.util.*;
12
class Solution {
2-
public int solution(int n, int[] lost, int[] reserve) {
3-
int[] people = new int[n];
3+
public int solution(int n, int[] losts, int[] reserves) {
4+
int[] student = new int[n];
5+
Arrays.fill(student,1);
6+
47
int answer = n;
8+
9+
for(int lost : losts) {
10+
student[lost-1] --;
11+
}
12+
13+
for(int reserve : reserves){
14+
student[reserve-1] ++;
15+
}
516

6-
for (int l : lost)
7-
people[l-1]--;
8-
for (int r : reserve)
9-
people[r-1]++;
10-
11-
for (int i = 0; i < people.length; i++) {
12-
if(people[i] == -1) {
13-
if(i-1>=0 && people[i-1] == 1) {
14-
people[i]++;
15-
people[i-1]--;
16-
}else if(i+1< people.length && people[i+1] == 1) {
17-
people[i]++;
18-
people[i+1]--;
19-
}else
20-
answer--;
17+
for(int i = 0 ; i < n; i ++){
18+
if(student[i] == 0){
19+
if(i > 0 && student[i-1] == 2) { // 왼쪽에서 빌림
20+
student[i-1] --;
21+
student[i] ++;
22+
} else if(i < n - 1 && student[i+1] == 2) { // 오른쪽에서 빌림
23+
student[i+1] --;
24+
student[i] ++;
25+
} else{
26+
answer --;
27+
}
2128
}
2229
}
30+
31+
2332
return answer;
2433
}
2534
}

0 commit comments

Comments
 (0)