Home > Back-end > A maximum difference sliding window algorithm
A maximum difference sliding window algorithm
Time:02-24
Stock business, by the biggest gain of the sliding O N the algorithm, or=y/x - 1, the position of x must be in front of the y, I now algorithm is directly O N the biggest gains, the algorithm complexity is O (M * N), M is the length of the array, and under the guidance algorithm faster,
CodePudding user response:
Can only say that under the optimization, In the current N between Japan and China, the minimum value in a, the maximum value in b; The next N Japan, after can be directly move N range to a At this point in the detection of maximum minimum, of course, also can be optimized,