import java.util.*;

class Solution {
    public Set<Integer> set = new TreeSet<>();
    public boolean[] visit;
    
    public int[] solution(int[] numbers) {
        int sum = 0;
        visit = new boolean[numbers.length];
        
        recur(0, numbers, sum);
        
        int[] answer = new int[set.size()];
        Iterator<Integer> iterator = set.iterator();
        for(int i=0; i<answer.length; i++) { answer[i] = iterator.next(); }
        
        return answer;
    }
    
    public void recur(int n, int[] numbers, int sum) {
        if(n==2) {
            System.out.println(sum);
            set.add(sum);
            return;
        }
        
        for(int i=0; i<numbers.length; i++) {
            if(visit[i]) { continue; }
            
            visit[i] = true;
            recur(n+1, numbers, sum+numbers[i]);
            visit[i] = false;
        }        
    }
}

'Problem Solving > Programmers' 카테고리의 다른 글

[Level 1] 최소직사각형  (0) 2022.03.24
[Level 1] 2016년  (0) 2022.03.24
[Level 1] 예산  (0) 2022.03.24
[Level 1] 3진법 뒤집기  (0) 2022.03.23
[Level 1] 약수의 개수와 덧셈  (0) 2022.03.23