최댓값과 최솟값

LJM·2023년 4월 3일
0

programmers

목록 보기
13/92

최소힙, 최대힙 으로 풀었다

이렇게 쉬운문제가 나오면 의심부터 하게된다;;

import java.util.*;

class Solution {
    public String solution(String s) {
        String answer = "";
        
        Queue<Integer> pq = new PriorityQueue<>();
        Queue<Integer> rpq = new PriorityQueue<>(Collections.reverseOrder());
        
        String[] input = s.split(" ");
        
        for(int i = 0; i < input.length; ++i)
        {
            pq.add(Integer.parseInt(input[i]));
            rpq.add(Integer.parseInt(input[i]));
        }
        
        answer = pq.poll() + " " + rpq.poll();
        
        
        return answer;
    }
}
profile
게임개발자 백엔드개발자

0개의 댓글