Beakjoon&프로그래머스/Java
[프로그래머스/Java] 두 개 뽑아서 더하기
현장
2025. 2. 25. 20:51
-Code
import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
class Solution {
public int[] solution(int[] numbers) {
List<Integer> answer = new ArrayList<>();
int numLen = numbers.length;
for (int i = 0; i < numLen; i++) {
for (int j = i + 1; j < numLen; j++) {
int numSum = numbers[i] + numbers[j];
if (!answer.contains(numSum)) answer.add(numSum);
}
}
Collections.sort(answer);
return answer.stream().mapToInt(Integer::intValue).toArray();
}
}