JAVA/프로그래머스
[프로그래머스/자바] 두 개 뽑아서 더하기
동백05
2024. 1. 15. 21:35
https://school.programmers.co.kr/learn/courses/30/lessons/68644
import java.util.*;
class Solution {
public int[] solution(int[] numbers) {
List<Integer> list = new ArrayList<Integer>();
for(int i=0;i<numbers.length-1;i++){
for(int j=i+1;j<numbers.length;j++){
int result = numbers[i]+numbers[j];
if(!list.contains(result)){
list.add(result);
}
}
}
int length = list.size();
int[] answer=new int[length];
for(int i=0;i<length;i++){
answer[i]=list.get(i).intValue();
}
Arrays.sort(answer);
return answer;
}
}