자료구조 & 알고리즘/우선순위큐

// nums 배열에 주어진 정수들 중에서 가장 많이 발생한 숫자들 순으로 k 번째 까지 출력하세요. // 빈도가 같은 경우에는 값이 작은 숫자가 먼저 출력되도록 구현하세요. // 입출력 예시 // 입력: 1, 1, 1, 2, 2, 3 // k: 2 // 출력: 1, 2 // 입력: 3, 1, 5, 5, 3, 3, 1, 2, 2, 1, 3 // k: 3 // 출력: 3, 1, 2 public class Practice { public static void solution1(int[] nums, int k) { // Map.Entry & Comparator로 풀기 // Map.Entry로 풀기 Map map = new HashMap(); for (int i = 0; i < nums.length; i++) ..
# Comparable 혹은 Comparator에서 ex) x, y -> x - y //오름차순 x, y -> y - x //내림차순 # 자바 우선순위큐 사용 예시 - 1. 기본 오름차순 정렬 - 2. 기본 내림차순 정렬 (reverse) - 3. Comparable 구현 정렬 - 4. Comparator 구현 정렬 - 5. 문자열(사전식) 정렬 // Comparable || Comparator 사용... class Person implements Comparable { String name; int age; public Person(String name, int age) { this.name = name; this.age = age; } @Override public int compareTo(Perso..
꾸준함의 미더덕
'자료구조 & 알고리즘/우선순위큐' 카테고리의 글 목록