본문 바로가기

프로그래머스

프로그래머스 - 두 개 뽑아서 더하기

import java.util.*;
class Solution {
    public int[] solution(int[] numbers) {
        int[] answer = {};
        Set <Integer> savePot = new HashSet<>();
        for(int i=0; i<numbers.length; i++){
            for(int j=i+1; j<numbers.length; j++){
               savePot.add(numbers[i]+numbers[j]);                 
            }
        }  
        return  savePot.stream().sorted().mapToInt(Integer::intValue).toArray();
    }
}

'프로그래머스' 카테고리의 다른 글

프로그래머스 - 올바른 괄호  (0) 2024.09.05
프로그래머스 - 방문 길이  (0) 2024.09.05
프로그래머스 - 행렬의 곱셈  (0) 2024.09.04
프로그래머스 - 실패율  (0) 2024.09.04
프로그래머스 - 모의고사  (1) 2024.09.03