Solution One: The time complexity is O (n*n), all groups of violence.
Solution Two: Time complexity of O (2*n).
Idea: Array preprocessing, constructing two auxiliary arrays--left interval array, right interval arrays. The maximum value of [0, I] is stored in the left interval array as l[i]. The maximum value of (I, N] is recorded as r[I], and the array is finally traversed.
Solution Three: Time complexity O (N).
Idea: Find the largest number in the array max, minus the difference between the smaller numbers at the end of the array with Max, or the answer if Max subtracts the value of another endpoint with Max at the endpoint. The proof is simple, so that the smallest number alone becomes an interval is the answer.
The main idea: to find out the array of any local minimum value, that is, the minimum point in mathematics is the subscript.
Solving ideas: Two-point solution. First, determine whether the two ends are minimum points, if not, the middle part of the two.
Problem-Solving ideas: (binary tree, the sequence of the method) first by the law fold several times. We found that the number of folds in the nth fold is 2^n-1, and we will find the following rules:
So we found that this is a left node is always down, the right node is always up two fork tree. The result is output in the order of the ordinal line.
Algorithmic thinking problem