sliding window(2)
-
[Leetcode] 1498. Number of Subsequences That Satisfy the Given Sum Condition
🗓️ Daily LeetCoding Challenge May, Day 6 class Solution: def numSubseq(self, nums: List[int], target: int) -> int: answer = 0 nums.sort() # O(NlogN) left, right = 0, len(nums) - 1 while left
2023.05.06 -
[Leetcode] 1456. Maximum Number of Vowels in a Substring of Given Length
🗓️ Daily LeetCoding Challenge May, Day 5 class Solution: def maxVowels(self, s: str, k: int) -> int: q = collections.deque(s[:k]) vowel = ['a', 'e', 'i', 'o', 'u'] count = 0 max_count = 0 for v in vowel: count += s[:k].count(v) max_count = max(max_count, count) i = k while i < len(s): if q.popleft() in vowel: count -= 1 x = s[i] q.append(x) if x in vowel: count += 1 max_count = max(max_count, co..
2023.05.06