-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
JangHongJoon
committed
May 2, 2024
1 parent
dbe6361
commit fc77b43
Showing
4 changed files
with
32 additions
and
44 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import java.util.*; | ||
|
||
class Solution { | ||
public int solution(int n, int[] lost, int[] reserve) { | ||
Arrays.sort(lost); | ||
Arrays.sort(reserve); | ||
int answer = n-lost.length; | ||
for (int i=0; i<lost.length; i++){ | ||
for (int j=0; j<reserve.length; j++){ | ||
if (lost[i] == reserve[j]){ | ||
answer++; | ||
lost[i] = -1; | ||
reserve[j] = -1; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
for (int i=0; i<lost.length; i++){ | ||
for (int j=0; j<reserve.length; j++){ | ||
if (lost[i]-1 == reserve[j] || lost[i]+1 == reserve[j]){ | ||
answer++; | ||
reserve[j]=-1; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
return answer; | ||
} | ||
} |