- Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy patharray-score.py
More file actions
Latest commit
27 lines (26 loc) · 800 Bytes
/
Copy patharray-score.py
File metadata and controls
27 lines (26 loc) · 800 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
classSolution:
"""
@param nums: the array to be scored.
@param k: the requirement of subarray length.
@param u: if the sum is less than u, get 1 score.
@param l: if the sum is greater than l, lose 1 score.
@return: return the sum of scores for every subarray whose length is k.
"""
defarrayScore(self, nums, k, u, l):
# write your code here.
ret=0
s=0
foriinrange(0, k):
s+=nums[i]
ifs<u:
ret+=1
ifs>l:
ret-=1
foriinrange(k, len(nums)):
s+=nums[i] -nums[i-k]
ifs<u:
ret+=1
ifs>l:
ret-=1
returnret
# easy: https://www.lintcode.com/problem/array-score/