본문 바로가기

Algorithm101

[그리디 알고리즘] 태스크 스케줄러 621 | Task Scheduler https://leetcode.com/problems/task-scheduler/ Given a characters array tasks, representing the tasks a CPU needs to do, where each letter represents a different task. Tasks could be done in any order. Each task is done in one unit of time. For each unit of time, the CPU could complete either one task or just be idle. However, there is a non-negative integer n that represents.. 2023. 3. 30.
[LeetCode] 896 | Monotonic Array 896 | Monotonic Array https://leetcode.com/problems/monotonic-array An array is monotonic if it is either monotone increasing or monotone decreasing. An array nums is monotone increasing if for all i 2023. 3. 29.
[그리디 알고리즘] 키에 따른 대기열 재구성 406 | Queue Reconstruction by Height https://leetcode.com/problems/queue-reconstruction-by-height/ You are given an array of people, people, which are the attributes of some people in a queue (not necessarily in order). Each people[i] = [hi, ki] represents the ith person of height hi with exactly ki other people in front who have a height greater than or equal to hi. Reconstruct and return the q.. 2023. 3. 28.
[그리디 알고리즘] 주식을 사고팔기 가장 좋은 시점Ⅱ 122 | Best Time to Buy and Sell Stock IIhttps://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/ You are given an integer array prices where prices[i] is the price of a given stock on the ith day.On each day, you may decide to buy and/or sell the stock. You can only hold at most one share of the stock at any time. However, you can buy it then immediately sell it on the same day.Find and.. 2023. 3. 24.
[BOJ] 1931 | 회의실 배정 1931 | 회의실 배정 https://www.acmicpc.net/problem/1931 문제 한 개의 회의실이 있는데 이를 사용하고자 하는 N개의 회의에 대하여 회의실 사용표를 만들려고 한다. 각 회의 I에 대해 시작시간과 끝나는 시간이 주어져 있고, 각 회의가 겹치지 않게 하면서 회의실을 사용할 수 있는 회의의 최대 개수를 찾아보자. 단, 회의는 한번 시작하면 중간에 중단될 수 없으며 한 회의가 끝나는 것과 동시에 다음 회의가 시작될 수 있다. 회의의 시작시간과 끝나는 시간이 같을 수도 있다. 이 경우에는 시작하자마자 끝나는 것으로 생각하면 된다. 입력 첫째 줄에 회의의 수 N(1 ≤ N ≤ 100,000)이 주어진다. 둘째 줄부터 N+1 줄까지 각 회의의 정보가 주어지는데 이것은 공백을 사이에 두.. 2023. 3. 23.
[해시 테이블] 상위 K 빈도 요소 347 | Top K Frequent Elements https://leetcode.com/problems/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: [1] Constraints: 1 원소1 : 원소1의 개수, 원소2 : 원소 2의 개수 개수에 따른 정렬이 필요하여 lambda 사용 item[1], 즉 .. 2023. 3. 22.
반응형