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,

CodePudding user response:

reference 1st floor GKatHere response:
can only say that, under the optimized
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
, of course, at this point in the test also can be optimized when the minimum value, the largest
in this line of thought can be, is a time when writing code, the if the else there will be many, is not very smooth feeling
  • Related