topic:
1124. The longest period of performance.md
Thought:
This question is not,I thought it was a double pointer but timeout over time,结果是Prefix and算法。The following isSpiritual godSolution
通过Prefix and,我们可以把Elements and elements of sub -array转换成两个Prefix and的差,Right now
$$
\sum_{j=left}^{right} nums[j] = \sum_{j=0}^{right} nums[j]− \sum_{j=0}^{left-1} nums[j]=s[right+1]−s[left]
$$
Now that I said it「Elements and elements of sub -array」,那么利用Prefix and s,Turn the problem to:
Find two bidding i and j,satisfy j<ij<ij<i and s[j]<s[i],maximize i−jValue。
Code:
1 | class Solution: |
1 | class Solution: |