Article Directory
Two minutes note
- The essence of dichotomy: two-stage (see rotating array). Monotonicity must be dichotomy, and dichotomy is not necessarily monotonic!
- The dichotomy must meet the boundary conditions, such as the dichotomy condition >=x, but the final dichotomy may be >x, and no = x. See the integer dichotomy template question.
- Dichotomous template, see y
Template question
Integer dichotomy
Floating point dichotomy
Index dichotomy
- 153. Find the smallest value in a rotated sorted array (classic problem, the essence of dichotomy: duality)
- 154. Find the minimum value II in the rotating sorted array (deleting and
nums[0]
repeating elements, transformed into the first question,最坏O(n)
the effect of repeating elements: if you repeat, you don't know whether the first half or the second half of the halves are divided) - 33. Search the rotating sorted array (find the minimum index point according to the above question, divide the array into two sections,
target <= nums.back()
judge whether it is in the front section or the back end, and then search for a number in binary in the ordered array) - 81. Search the rotating sorted array II (Similarly, delete and
nums[0]
duplicate elements are converted to question I. If there are duplicates, I don't know whether the dichotomy is the first half or the second half) - 704. Binary search (template question)
- 35. Search for the insertion position (may be inserted at the end, considering the boundary)
- 34. Find the first and last position of an element in a sorted array (template question)
- 74. Search for two-dimensional matrix (coordinate transformation,
/m %m
) - 162. Find Peak
- 274. H Index
- 275. H Index II
- 540. A single element in an ordered array
Range dichotomy
69. Square root of x (note overflow, boundary)
367. Effective perfect square number (multiplying two numbers is easy to burst int)