목록그리디 (88)
넘치게 채우기
https://leetcode.com/problems/water-bottles/description/leetcode - water bottles문제 유형 : 구현, 그리디문제 난이도 : Easy 문제There are numBottles water bottles that are initially full of water. You can exchange numExchange empty water bottles from the market with one full water bottle.The operation of drinking a full water bottle turns it into an empty bottle.Given the two integers numBottles and numExchange,..
https://leetcode.com/problems/minimum-difference-between-largest-and-smallest-value-in-three-moves/description/leetcode - Minimum Difference Between Largest and Smallest Value in Three Moves문제 유형 : 그리디, 정렬, 슬라이딩 윈도우문제 난이도 : Medium 문제You are given an integer array nums.In one move, you can choose one element of nums and change it to any value.Return the minimum difference between the largest and ..
https://leetcode.com/problems/intersection-of-two-arrays-ii/description/leetcode - Intersection of Two Arrays II문제 유형 : 그리디, 정렬문제 난이도 : Easy 문제Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must appear as many times as it shows in both arrays and you may return the result in any order. 두 정수 nums1과 nums2가 주어진다. 두 배열의 합집합을 구하시오.요소는 여러 번 ..
https://leetcode.com/problems/three-consecutive-odds/description/leetcode - Three Consecutive Odds문제 유형 : 그리디, 배열문제 난이도 : Easy 문제Given an integer array arr, return true if there are three consecutive odd numbers in the array. Otherwise, return false.정수 배열 arr이 주어진다.홀수 3개가 붙어있으면 true를 반환하라.아니면 false를 반환하라. 풀이streak변수를 만들어서 몇 개 째 붙어 있는지 확인한다.3번붙은적있다면 True를, 그런일없이 배열을 순회하면 false를 반환한다. 코드C++#pragma..
https://leetcode.com/problems/maximum-total-importance-of-roads/description/leetcode - Maximum Total Importance of Roads문제 유형 : 그리디, 우선순위 큐, 그래프문제 난이도 : Medium 문제You are given an integer n denoting the number of cities in a country. The cities are numbered from 0 to n - 1.You are also given a 2D integer array roads where roads[i] = [ai, bi] denotes that there exists a bidirectional road connecti..
https://leetcode.com/problems/minimum-number-of-k-consecutive-bit-flips/description/leetcode - Minimum Number of K Consecutive Bit Flips문제 유형 : 그리디 / 비트마스킹 / 슬라이딩 윈도우문제 난이도 : Hard 문제You are given a binary array nums and an integer k.A k-bit flip is choosing a subarray of length k from nums and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0.Return the minim..
https://leetcode.com/problems/minimum-number-of-days-to-make-m-bouquets/description/leetcode - Minimum Number of Days to Make m Bouquets문제 유형 : 이진탐색, 그리디, 슬라이딩 윈도우, 구현문제 난이도 : Medium 문제You are given an integer array bloomDay, an integer m and an integer k.You want to make m bouquets. To make a bouquet, you need to use k adjacent flowers from the garden.The garden consists of n flowers, the ith f..
https://leetcode.com/problems/most-profit-assigning-work/description/leetcode - Most Profit Assigning Work문제 유형 : 정렬, 그리디, 이진탐색문제 난이도 : Medium 문제You have n jobs and m workers. You are given three arrays: difficulty, profit, and worker where:difficulty[i] and profit[i] are the difficulty and the profit of the ith job, andworker[j] is the ability of jth worker (i.e., the jth worker can only comple..
https://leetcode.com/problems/patching-array/description/leetcode - Patching Array문제 유형 : 그리디문제 난이도 : Hard 문제Given a sorted integer array nums and an integer n, add/patch elements to the array such that any number in the range [1, n] inclusive can be formed by the sum of some elements in the array.Return the minimum number of patches required. 정수 배열 nums와 정수 n이 주어진다. 배열에 요소를 추가하여 닫힌구간 [1, n]의 모든..
https://leetcode.com/problems/minimum-increment-to-make-array-unique/description/leetcode - Minimum Increment to Make Array Unique문제 유형 : 정렬, 그리디문제 난이도 : Medium 문제You are given an integer array nums. In one move, you can pick an index i where 0 and increment nums[i] by 1.Return the minimum number of moves to make every value in nums unique.The test cases are generated so that the answer fits in..