BOJ - 10867

아이모·2022년 11월 21일
0

BOJ 길라잡이

목록 보기
4/9

1. 문제

https://www.acmicpc.net/problem/10867

2. 풀이

중복 제거하기 : if문 or Set
정렬 : 정렬 메소드 사용

import java.util.*;
import java.io.*;

public class Main10867 {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();
        int N = sc.nextInt();
        ArrayList<Integer> numList = new ArrayList<>();
        for(int i = 0; i < N; i++) {
            int num = sc.nextInt();
            if(!numList.contains(num))
                numList.add(num);
        }
        numList.sort(null);
        for(int num : numList){
            sb.append(num).append(" ");
        }
        sb.delete(sb.length()-1, sb.length());
        System.out.print(sb.toString());
    }
}

3. 적용된 알고리즘

정렬

profile
데이터로 보는 실력

0개의 댓글