Analysis of the problem, only to determine whether there are Ai = i in an array of integers, you can instead judge the linear array of integers, and (Ai = i is an over the origin of a line with a slope of 1) whether there is a point of intersection.
The presence of intersections has the following conditions
1, the slope of the integer array equals 1: or repeat or no intersection
2, the slope of the integer array is greater than 1: only if the smallest point of the integer array, located below the AI = I line, the maximum point of the integer array, is located in the AI = I this line above, there may be intersection
3, the slope of the integer array is less than 1: only if the smallest point of the integer array, located above the AI = I line, the maximum point of the integer array, is located in the AI = i this line below, there may be intersection
So:
if (A1 < 1)
{
if (a > N) return True;
else return False;
}
else if (A1 = = 1) return True;
Else
{
if (a < n) return ture;
else return False;
}
}
The problem is deduced: Finding the intersection point I.
First, if there is a intersection, when there is a point of intersection, use the binary method to find the intersection.