import java.util.stream.Collectors;
import java.util.*;
class Solution {
public int[] solution(int[] arr, int[] delete_list) {
List<Integer> answer = Arrays.stream(arr)
.boxed()
.collect(Collectors.toList());
List<Integer> deleteList = Arrays.stream(delete_list)
.boxed()
.collect(Collectors.toList());
answer.removeIf(deleteList::contains);
return answer.stream().mapToInt(Integer::intValue).toArray();
}
}
chatGPT 도움을 받은거라 그냥 혼자서도 함 해봄.
import java.util.*;
class Solution {
public int[] solution(int[] arr, int[] delete_list) {
List<Integer> answer = new ArrayList<>();
for(int i=0; i<arr.length; i++) {
int k = 0;
for(int j : delete_list) {
if(arr[i] == j)
k++;
}
if (k==0) answer.add(arr[i]);
}
return answer.stream().mapToInt(Integer::intValue).toArray();
}
}
contains() 쓰려고 했는데 Collection 인터페이스 상속한 클래스에서만 사용 가능하더라...
'Study with me > 프로그래머스 L0 마스터하기' 카테고리의 다른 글
프로그래머스 - L0 x사이의개수 (0) | 2023.12.29 |
---|---|
프로그래머스 - L0 할일목록 (0) | 2023.12.28 |
프로그래머스 - L0 홀수vs짝수 // 삼항 연산자 (2) | 2023.12.26 |
프로그래머스 - L0 순서바꾸기 (0) | 2023.12.25 |
프로그래머스 - L0 공백으로구분하기2 // 정규표현식 (0) | 2023.12.22 |