728x90
https://leetcode.com/problems/count-subarrays-where-max-element-appears-at-least-k-times
class Solution:
def countSubarrays(self, nums: List[int], k: int) -> int:
count = 0
maximum = max(nums)
if nums.count(maximum) < k:
return count
maximum_list = []
f = 0
for i in range(len(nums)):
if nums[i] == maximum:
maximum_list.append(i)
if len(maximum_list) >= k:
count += maximum_list[len(maximum_list) - k] + 1
return count
728x90
'IT > 코딩테스트' 카테고리의 다른 글
[Leetcode] 58. Length of Last Word (1) | 2024.04.01 |
---|---|
[Leetcode] 3099. Harshad Number (0) | 2024.03.31 |
[Leetcode] 41. First Missing Positive (1) | 2024.03.26 |
[Leetcode] 442. Find All Duplicates in an Array (0) | 2024.03.25 |
[Leetcode] 287. Find the Duplicate Number (0) | 2024.03.24 |