随笔分类 - AL_Two Pointers
摘要:350. Intersection of Two Arrays II 题目:和前面不一样的是,它允许出现多个次数。 Counter 利用两个Counter来进行统计,需要注意的是,需要取两个Counter中个数的较小值,时间复杂度为O(min(m, n)) import collections cl
阅读全文
摘要:209. Minimum Size Subarray Sum 题意:找到和为给定值的最小连续区间 O(n) 暴力 TLE class Solution(object): def minSubArrayLen(self, s, nums): """ :type s: int :type nums: L
阅读全文
摘要:18. 4Sum 思路:先排序(要使用Two Pointers必须排序),然后选择两个结点,剩下的两个结点通过Two Pointers来决定。 class Solution(object): def fourSum(self, nums, target): """ :type nums: List[
阅读全文
摘要:16. 3Sum Closest 思路:先进行排序(不然后面的两个指针不知道怎么移动),选中一个,再利用Two Pointers选择剩下的两个数,如下: class Solution(object): def threeSumClosest(self, nums, target): """ :typ
阅读全文
摘要:11. Container With Most Water 没看清楚题目,题中让选中两条线,使其能够装下最多的水。 思路如下: class Solution(object): def maxArea(self, height): """ :type height: List[int] :rtype:
阅读全文