[백준] 10867. 중복 빼고 정렬하기(실버5)
백준(실버5) - 10867. 중복 빼고 정렬하기(실버5)
풀이
자료구조의 특성을 이용하면 쉽게 풀 수 있는 문제이다.
Set을 사용하면 된다! Set중에 HashSet과 TreeSet이 있는데 HashSet은 음수까지는 정렬이 잘 안된다. 그 이유는 다음 포스팅에...
이 차이를 잘 모르고 HashSet에 데이터를 넣고 ArrayList에 옮겨서 다시 정렬해주는 수고가 들었다..
package com.algoStudy;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;
public class BOJ10867 {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
StringTokenizer st = new StringTokenizer(br.readLine());
Set<Integer> numbers = new HashSet();
for(int i=0; i<n; i++) {
numbers.add(Integer.parseInt(st.nextToken()));
}
List list = new ArrayList(numbers);
Collections.sort(list);
String result = list.toString().replace("[", "").replace(",", "").replace("]", "");
System.out.println(result);
}
}
Author And Source
이 문제에 관하여([백준] 10867. 중복 빼고 정렬하기(실버5)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@humblechoi/백준-10867.-중복-빼고-정렬하기실버5저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)