滑动窗口
BlackMan_阿伟
不积跬步无以至千里
展开
-
Feburary——1052.爱生气的书店老板
class Solution: def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int: size = len(customers) Sum_pre = 0 #不生气的状态下有多少顾客 for i in range(len(grumpy)): if grumpy[i]==0: ...原创 2021-02-23 11:01:21 · 268 阅读 · 0 评论 -
Feburary——1438. 绝对差不超过限制的最长连续子数组(滑动窗口)
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: #利用第三方库,将列表有序化,底层其实是一个最小堆 from sortedcontainers import SortedList left, right = 0, 0 size = len(nums) s = SortedLi...原创 2021-02-22 16:55:17 · 533 阅读 · 0 评论 -
February——424. 替换后的最长重复字符
class Solution: def characterReplacement(self, s: str, k: int) -> int: res = 0 right,left = 0,0 size = len(s) counter = Counter() while right<size: counter[s[right]]+=1 #在一个窗口内...原创 2021-02-19 16:15:22 · 94 阅读 · 0 评论 -
February——485.最大连续1的个数I,II
class Solution: def findMaxConsecutiveOnes(self, nums: List[int]) -> int: #滑动窗口法 res = 0 i = 0 windows = [] tmp = 0 while i<len(nums): if nums[i]!=0: ...原创 2021-02-19 15:27:32 · 138 阅读 · 0 评论