随笔分类 - 贪心
摘要:problem: https://leetcode.com/problems/advantage-shuffle/ In ordered to maximize the advantage of array A with respect to B, we had better choose the
阅读全文
摘要:problem: https://leetcode.com/problems/three-equal-parts/ 首先,检测有多少个1,记作x,看是不是3的倍数。不是则说明不存在对应划分。 之后,检测末尾的0,作为每个二进制数末尾的0个数,记作y。 最后,检测是否存在3个连续、不相交的,总共包含
阅读全文
摘要:problem:https://leetcode.com/contest/weekly-contest-148/problems/decrease-elements-to-make-array-zigzag/ 贪心题。有两种可能的zigzag,一个是奇数下标为最大值,一个是偶数下标为最大值。分别就这
阅读全文
摘要:problem:https://leetcode.com/problems/minimum-domino-rotations-for-equal-row/ 有四种可能性,相等数字为A[0],出现在上面或下面;相等数字为B[0],出现在上面或下面。取这四者最小值即可。
阅读全文
摘要:problem:https://leetcode.com/problems/score-after-flipping-matrix/ 一道贪心题,按照正常人的思路(而不是计算机的思路)去翻转就行了。说起来第一次看的时候有点懵逼,可能我更加习惯计算机的思维方式? (1) 只在第一列翻转行,通过行翻转把
阅读全文
摘要:problem:https://leetcode.com/problems/candy/ 一道贪心题,先从左往右扫一遍,保证右边比左边高分的拿到更多糖果,再从右往左扫一遍,保证左边比右边分高的拿到更多糖果,时间复杂度O(N)。 第一次的算法是顺序更新,O(N^2)的,每次发现右边比左边大还要回去更新
阅读全文

浙公网安备 33010602011771号