![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
greedy algorithm
复醉
这个作者很懒,什么都没留下…
展开
-
122. Best Time to Buy and Sell Stock II\\714. Best Time to Buy and Sell Stock with Transaction Fee
122. Best Time to Buy and Sell Stock II思路:极大值减去极小值,所以适合 贪心算法,把nums[x+1]-nums[x]加在一起,就得到所有极大值减去极小值之和,也就是最大利润。class Solution: def maxProfit(self, prices): """ :type prices: List[...原创 2018-11-15 17:06:45 · 114 阅读 · 0 评论 -
134. Gas Station
有2个东西在前面明确一下:很明显的如果sum(gas)<sum( cost)则不能跑完。如果sum(gas)>=sum(cost),则存在相应的起始点跑完一圈。具体2怎么证明,用数学公式,我还真想不出来。如果在某一节点,没有油了,则在该节点下一节点重新开始。class Solution: def canCompleteCircuit(self, gas, cost...原创 2018-11-19 11:11:46 · 126 阅读 · 0 评论 -
55. Jump Game/45. Jump Game II
55. Jump Game思路:[greedy] 得到所能走到的最大距离,与最终结果比较class Solution: def canJump(self, nums): """ :type nums: List[int] :rtype: bool """ max_nums=nums[0] ..原创 2018-11-15 12:12:46 · 118 阅读 · 0 评论 -
757. Set Intersection Size At Least Two
刚开始的时候看错题了,看成求最小区间,不过方向没有偏本题还在greedy目录下,具体看注释。# 757. Set Intersection Size At Least Two# # 一次遍历,覆盖所有class Solution: def intersectionSizeTwo(self, intervals): """ :type inter...原创 2018-11-23 16:28:16 · 221 阅读 · 0 评论 -
jupyter notebook 修改启动目录,并使用快捷方式(win10)
本人比较懒,经过一番查询,得到了jupyter notebook 的快速启动方式找到jupyter notebook 快捷方式,按Windows键(“Winkey”),再程序里面扒拉扒拉,就扒拉到了。然后找到它的属性,把圈中的部分改成你的目录就行了最后把快捷方式放在桌面什么都行...原创 2018-11-22 13:21:47 · 4468 阅读 · 0 评论 -
502. IPO
502. IPO假设 LeetCode 即将开始其 IPO。为了以更高的价格将股票卖给风险投资公司,LeetCode希望在 IPO 之前开展一些项目以增加其资本。 由于资源有限,它只能在 IPO 之前完成最多 k 个不同的项目。帮助 LeetCode 设计完成最多 k 个不同项目后得到最大总资本的方式。给定若干个项目。对于每个项目 i,它都有一个纯利润 Pi,并且需要最小的资本 Ci 来启动...原创 2018-11-22 13:47:22 · 152 阅读 · 0 评论 -
881. Boats to Save People
贪心要排序,具体在注释# 881. Boats to Save People# # 让最重最轻一起走,超重,则自己走class Solution: def numRescueBoats(self, people, limit): """ :type people: List[int] :type limit: int ...原创 2018-11-29 16:45:57 · 224 阅读 · 0 评论 -
765. Couples Holding Hands
看看没有什么思路,参考了其他人的博客,直接贪心就能得到正确答案。(证明不会)这里用到了位运算中的异或省了好多事。# 765. Couples Holding Hands# # 这道是经典的贪心算法题,贪得我摸不着头脑class Solution: def minSwapsCouples(self, row): """ :type row: Li...原创 2018-11-29 19:47:31 · 211 阅读 · 0 评论