贪心算法
0 人感兴趣 · 16 次引用
- 最新
- 推荐

leetcode 665. Non-decreasing Array 非递减数列 (中等)
最多只有一次修改某个数字的机会,问能否将数组变为非递减数组。

leetcode 406. Queue Reconstruction by Height 根据身高重建队列 (中等)
这题先要理解题,一个无序数组,数组中每个元素有两个属性,一个表示身高,一个表示前面有几个人和他一样高或更高。现在要把这个数组按其属性排列正确。

leetcode122. Best Time to Buy and Sell Stock II 买卖股票的最佳时机 II(简单)
每天可以无限次买卖,但是只能持有一支股票。想有最大利润,就得低价买高价卖。如果第二天价格比当前价格高,我们就卖出,把差价加入利润中。若后天价格更高,我们还可以在第二天卖出后再买入。以此类推,遍历完整个数组后即可获得最大利润。

leetcode 763. Partition Labels 划分字母区间 (中等)
一个字符串S,将其尽可能多的分割为子字符串,条件是每种字符最多只能出现在一个子串中。上面的示例中,字符串S中有多个a,这些a必须只能在第一个子串中,字母e出现在第二个子串中。这道题难点就是如何找到字符串的断点,即拆分成为子串的位置。

leetcode 452. Minimum Number of Arrows to Burst Balloons 用最少数量的箭引爆气球 (中等)
区间重叠问题,一般都要想到贪心(局部最优等于全局最优)


leetcode 435. Non-overlapping Intervals 无重叠区间 (中等)
求最小的移除区间个数,等价于尽量多保留不重叠的区间。在选择要保留区间时,区间的结尾十分重要:选择的区间结尾越小,余留给其它区间的空间就越大,就越能保留更多的区间。因此我们采取的贪心策略为:优先保留结尾小且不相交的区间。

leetcode 135. Candy 分发糖果 (困难)
通过两次遍历,分配的糖果就可以满足题目要求了。这里的贪心策略即为,在每次遍历中,只考虑并更新相邻一侧的大小关系。

leetcode 455. Assign Cookies 分发饼干 (简)
使用贪心策略是,给剩余孩子里最小饥饿度的孩子分配最小的能饱腹的饼干。

贪心:柠檬水找零、跳跃游戏🍋
以前我也曾经刷过一段时间的leetcode,后来因为比较忙,所以停了好久了。现在来开始重新满满刷起来,毕竟只是位前端,还是继续使用JavaScript进行编写代码(最熟悉一些)


