There are now a large number of natural numbers composed of small to large arrays of arr, which will have 123456910 to find 6 (the first discontinuous number)
Example: "12356789" found 3
"012345678" Found 8
The first type: Traversal array to determine whether the difference is 1, the return value of the algorithm time complexity O (n)
The second type:
/* Transmission direction: Command machine? user * Instruction length: A total of 3 bytes * Description: This instruction is a cumulative answer, the sequence number in the instruction indicates that the command has received all the positioning records of the serial number, for example: * Assuming that the command has received a positional record sequence number of 0,1,2,3,5,6,8, the sequence number in the received answer instruction should be 3. */public static int Sh (int le, int r, int[] arr) { if (le + 1 = = r) return Arr[le]; int mid = (Le + r)/2; if (arr[mid] = = mid) return Sh (Mid, R, arr); if (Arr[mid]! = Mid) return Sh (0, Mid, arr); return mid; }
Obviously the second algorithm has a time complexity of: O (LOGN)
Above!
How to quickly find the first discontinuous number n in a sorted array