
Greedy
文章平均质量分 75
flyatcmu
这个作者很懒,什么都没留下…
展开
-
Maximum Number of Events That Can Be Attended
You are given an array ofeventswhereevents[i] = [startDayi, endDayi]. Every eventistarts atstartDayiand ends atendDayi.You can attend an eventiat any daydwherestartTimei<= d <= endTimei. You can only attend one event at any timed.R...原创 2022-03-16 01:57:49 · 362 阅读 · 0 评论 -
Construct String With Repeat Limit
You are given a stringsand an integerrepeatLimit. Construct a new stringrepeatLimitedStringusing the characters ofssuch that no letter appearsmore thanrepeatLimittimesin a row. You donothave to use all characters froms.Returnthelexicograp...原创 2022-02-20 12:20:24 · 167 阅读 · 0 评论 -
Non-overlapping Intervals
Given a collection of intervals, find the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping.Example 1:Input: [[1,2],[2,3],[3,4],[1,3]]Output: 1Explanation: [1,3] can be removed and the rest of intervals原创 2020-05-19 12:31:57 · 497 阅读 · 0 评论 -
Can Place Flowers
You have a long flowerbed in which some of the plots are planted, and some are not. However, flowers cannot be planted inadjacentplots.Given an integer arrayflowerbedcontaining0's and1's, where0means empty and1means not empty, and an integern,...原创 2022-02-10 15:08:58 · 218 阅读 · 0 评论 -
Minimum Moves to Reach Target Score
You are playing a game with integers. You start with the integer1and you want to reach the integertarget.In one move, you can either:Incrementthe current integer by one (i.e.,x = x + 1). Doublethe current integer (i.e.,x = 2 * x).You can use t...原创 2022-01-16 12:20:09 · 333 阅读 · 0 评论 -
Gas Station
There are N gas stations along a circular route, where the amount of gas at stationi is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from stationi to it原创 2014-03-01 15:52:03 · 530 阅读 · 0 评论 -
Furthest Building You Can Reach
You are given an integer arrayheightsrepresenting the heights of buildings, somebricks, and someladders.You start your journey from building0and move to the next building by possibly using bricks or ladders.While moving from buildingito buildin...原创 2020-11-01 13:21:27 · 418 阅读 · 0 评论 -
Maximum Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array[-2,1,-3,4,-1,2,1,-5,4],the contiguous subarray[4,-1,2,1]has ...原创 2016-10-16 11:24:35 · 262 阅读 · 0 评论 -
Maximum Number of Non-Overlapping Subarrays With Sum Equals Target
Given an arraynumsand an integertarget.Return the maximum number ofnon-emptynon-overlappingsubarrays such that the sum of values in each subarray is equal totarget.Example 1:Input: nums = [1,1,1,1,1], target = 2Output: 2Explanation: There a...原创 2020-08-09 13:23:02 · 239 阅读 · 1 评论 -
Minimum Swaps to Arrange a Binary Grid
Given annx nbinarygrid, in one step you can choose twoadjacent rowsof the grid and swap them.A grid is said to bevalidif all the cells above the main diagonal arezeros.Returnthe minimum number of stepsneeded to make the grid valid, or-1if ...原创 2020-08-03 02:03:05 · 194 阅读 · 0 评论 -
Bulb Switcher IV
There is a room withnbulbs, numbered from0ton-1,arranged in a row from left to right. Initially all the bulbs areturned off.Your task is to obtain the configuration represented bytargetwheretarget[i]is '1' if the i-th bulb is turned on and is ...原创 2020-07-26 12:56:07 · 178 阅读 · 0 评论 -
Minimum Number of Refueling Stops
A car travels from a starting position to a destination which istargetmiles east of the starting position.Along the way, there are gas stations. Eachstation[i]represents a gas station that isstation[i][0]miles east of the starting position, and ha...原创 2020-06-24 14:15:31 · 257 阅读 · 0 评论 -
Stamping The Sequence
You want to form atargetstring oflowercase letters.At the beginning, your sequence istarget.length'?'marks. You also have astampof lowercase letters.On each turn, you may place the stamp over the sequence, and replace every letter in the seque...原创 2020-06-14 05:51:00 · 268 阅读 · 0 评论 -
Minimum Number of K Consecutive Bit Flips
In an arrayAcontaining only 0s and 1s, aK-bit flipconsists of choosing a (contiguous) subarray of lengthKand simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0.Return the minimum number ofK-bit flips required so...原创 2020-06-13 11:10:40 · 177 阅读 · 0 评论 -
Queue Reconstruction by Height
Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers(h, k), wherehis the height of the person andkis the number of people in front of this person who have a height greater than or equal toh. Wri...原创 2020-06-08 12:11:12 · 170 阅读 · 0 评论 -
Jump Game
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine if yo...原创 2014-01-29 13:52:11 · 603 阅读 · 0 评论 -
Course Schedule III
There arendifferent online courses numbered from1ton. Each course has some duration(course length)tand closed ondthday. A course should be takencontinuouslyfortdays and must be finished b...原创 2020-04-30 10:16:30 · 250 阅读 · 0 评论 -
Minimum Cost to Connect Sticks
You have somestickswithpositive integer lengths.You can connect any two sticks of lengthsXandYinto one stickby paying a cost ofX + Y. You perform this action until there is one stick remai...原创 2020-03-29 12:06:59 · 206 阅读 · 0 评论 -
Greedy 类型题总结
placeholder for greedy problem.原创 2020-02-17 11:48:00 · 420 阅读 · 0 评论