Skip to content

Commit

Permalink
Add #6 체육복 - 박지원
Browse files Browse the repository at this point in the history
  • Loading branch information
since1909 committed Nov 30, 2024
1 parent 88a195f commit 4e9dbd8
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions greedy/체육복/박지원.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import java.util.Arrays;

class Solution {
public int solution(int n, int[] lost, int[] reserve) {
Arrays.sort(lost);
Arrays.sort(reserve);

int getCount = 0;
for (int i = 0; i < lost.length; i++) {
for (int j = 0; j < reserve.length; j++) {
if (lost[i] == reserve[j]) {
lost[i] = -1;
reserve[j] = -1;
getCount++;
break;
}
}
}

for (int lostj : lost) {
if (lostj == -1) continue;
for (int j = 0; j < reserve.length; j++) {
if (reserve[j] == -1) continue;
if (lostj == reserve[j] - 1 || lostj == reserve[j] + 1) {
reserve[j] = -1;
getCount++;
break;
}
}
}
return n - lost.length + getCount;
}
}

0 comments on commit 4e9dbd8

Please sign in to comment.