My Space

반응형

코드
public int[] solution(int[] numbers) {				
		HashSet<Integer> hs = new HashSet<Integer>();		
		for(int i=0; i<numbers.length; i++) {
			for(int j=i+1; j<numbers.length; j++) {	
					if(!hs.contains(numbers[i]+numbers[j])) {
						hs.add(numbers[i]+numbers[j]);
					}
			}
		}		
		int[] answer = new int[hs.size()];
		int cnt = 0;
		for(int i : hs) {
			answer[cnt] = i;
			cnt++;
		}		
		Arrays.sort(answer);	
		return answer; 
	}

공유하기

facebook twitter kakaoTalk kakaostory naver band
loading