This commit is contained in:
parent
c5540e8fa6
commit
dd5dcd1f20
1 changed files with 19 additions and 0 deletions
19
medium/count_the_hidden_sequences.py
Normal file
19
medium/count_the_hidden_sequences.py
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
# https://leetcode.com/problems/count-the-hidden-sequences
|
||||
|
||||
from typing import List
|
||||
|
||||
class Solution:
|
||||
def numberOfArrays(self, differences: List[int], lower: int, upper: int) -> int:
|
||||
total = 0
|
||||
min_sum = 0
|
||||
max_sum = 0
|
||||
for diff in differences:
|
||||
total += diff
|
||||
min_sum = min(min_sum, total)
|
||||
max_sum = max(max_sum, total)
|
||||
|
||||
min_start = lower - min_sum
|
||||
max_start = upper - max_sum
|
||||
|
||||
return max(0, max_start - min_start + 1)
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue