Skip to content

Commit 9c45423

Browse files
committed
Time: 31 ms (33.77%), Space: 17.8 MB (83.64%) - LeetHub
1 parent e17dde7 commit 9c45423

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution:
2+
def findXSum(self, nums: List[int], k: int, x: int) -> List[int]:
3+
n = len(nums)
4+
ans = []
5+
for i in range(n-k+1):
6+
cnt = Counter(nums[i:i+k])
7+
freq = sorted(cnt.items(), key=lambda v : (-v[1], -v[0]))
8+
xsum = sum(k*v for k, v in freq[:x])
9+
ans.append(xsum)
10+
return ans

0 commit comments

Comments
 (0)