Data Structure & Algorithms/Heaps2 [Heaps] Leetcode347.Top K Frequent Elements https://leetcode.com/problems/top-k-frequent-elements/ Top K Frequent Elements - LeetCode Top K Frequent Elements - Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order. Example 1: Input: nums = [1,1,1,2,2,3], k = 2 Output: [1,2] Example 2: Input: nums = [1], k = 1 Output: leetcode.com 자 다시 꾸준하게 자료구조/알고리즘의 늪으로 빠져보자. 구하고자하는것: k .. 2023. 2. 22. [Heaps] heap 개념알아보기 출처: leetcode 힙이란 데이터를 저장하는 컨테이너로 Priority queue 로도 불린다. 다음과같은 오퍼레이션이있다. Add an element in O(logn) Remove the minimum element in O(logn) Find the minimum element in O(1) *힙으로는 최대 요소값을 찾을수있으며 최대값을 찾거나 제거할때는 max heap이라불리면 최소값을 찾거나 제거할때는 min heap이라 불린다. Implementation 해쉬맵과 같이 힙도 대부분의 프로그램 언어에서 기본적 라이브러리가 제공되기 때문에 굳이 작동 코드를 알아야할 필요는 없지만 인터페이스를 이해해야한다. 허나 인터뷰에서는 해쉬맵과는다르게 heap의 implementation을 알아야한다. .. 2023. 2. 15. 이전 1 다음