-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path42862.js
More file actions
25 lines (22 loc) · 689 Bytes
/
42862.js
File metadata and controls
25 lines (22 loc) · 689 Bytes
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
function solution(n, lost, reserve) {
lost = lost.sort((a,b)=>a-b);
reserve = reserve.sort((a,b)=>a-b);
for(let i=0; i<reserve.length; i++){
if(lost.indexOf(reserve[i])!==-1){
lost.splice(lost.indexOf(reserve[i]),1);
reserve.splice(i,1);
i--;
}
}
var answer = n-lost.length;
for(let i=0; i<lost.length; i++){
if(reserve.indexOf(lost[i]-1)!==-1){
answer++;
reserve.splice(reserve.indexOf(lost[i]-1),1);
}else if(reserve.indexOf(lost[i]+1)!==-1){
answer++;
reserve.splice(reserve.indexOf(lost[i]+1),1);
}
}
return answer;
}