File tree Expand file tree Collapse file tree 2 files changed +28
-19
lines changed
Expand file tree Collapse file tree 2 files changed +28
-19
lines changed Original file line number Diff line number Diff line change 44
55### 성능 요약
66
7- 메모리: 82.4 MB, 시간: 0.03 ms
7+ 메모리: 73.7 MB, 시간: 0.04 ms
88
99### 구분
1010
1616
1717### 제출 일자
1818
19- 2025년 01월 26일 23:53:43
19+ 2025년 09월 05일 13:06:12
2020
2121### 문제 설명
2222
Original file line number Diff line number Diff line change 1+ import java .util .*;
12class 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}
You can’t perform that action at this time.
0 commit comments