강의로 돌아가기

### 테스트 케이스 3,7번에서 틀리다고 나오네요;;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
class Solution {
public int solution(int n, int[] lost, int[] reserve) {

int[] array = new int[n+1];

for(int i=0;i<lost.length;i++) {
array[lost[i]] = 1;
}

int lostLen = lost.length;

for(int i=0;i0;i++) {
if((reserve[i]+1 < n+1) && (array[reserve[i]+1] == 1)) {
array[reserve[i]+1] = 0;

lostLen--;
}else if((reserve[i]-1 > 0) &&(array[reserve[i]-1] == 1)) {
array[reserve[i]-1] = 0;
lostLen--;
}
}

int p = 0;
for(int i=0;i<array.length;i++) {
if(array[i]== 0) {
p++;
}
}
return p-1;
}
}

뭐가 틀린지 모르겠습니다.ㅠ.ㅠ. 고수들의 답변 기다릴게요 ㅠㅠ

###### 작성중인 코드―Solution.java
``````1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
class Solution {
public int solution(int n, int[] lost, int[] reserve) {
int[] array = new int[n+1];

for(int i=0;i<lost.length;i++) {
array[lost[i]] = 1;
}

int lostLen = lost.length;

for(int i=0;i<reserve.length&&lostLen>0;i++) {
if((reserve[i]+1 < n+1) && (array[reserve[i]+1] == 1)) {
array[reserve[i]+1] = 0;
lostLen--;
}else if((reserve[i]-1 > 0) &&(array[reserve[i]-1] == 1)) {
array[reserve[i]-1] = 0;
lostLen--;
}
}

int p = 0;
for(int i=0;i<array.length;i++) {
if(array[i]== 0) {
p++;
}
}
return p-1;
}
}
``````