LeetCode常见题型——二分查找

1. 算法思想

二分查找(又叫二分法,折半查找)每次在查找时通过将待查区间分为两部分并只取一部分继续查找。对于一个长度为O(n)的数组,二分查找的时间复杂度为O(log(n))。

C++等语言习惯使用左闭右开区间, 当然也可选用左闭右闭的方式。

二分查找可以看作是双指针的特殊情况。

2. 常见题型

LeetCode-153. Find Minimum in Rotated Sorted Array [C++][Java]_贫道绝缘子的博客-CSDN博客Given the sorted rotated arraynumsofuniqueelements, returnthe minimum element of this array.https://blog.csdn.net/qq_15711195/article/details/123057907LeetCode-154. Find Minimum in Rotated Sorted Array II [C++][Java]_贫道绝缘子的博客-CSDN博客Given the sorted rotated arraynumsthat may containduplicates, returnthe minimum element of this array.https://blog.csdn.net/qq_15711195/article/details/123037392LeetCode-4. Median of Two Sorted Arrays [C++][Java]_贫道绝缘子的博客-CSDN博客Given two sorted arraysnums1andnums2of sizemandnrespectively, returnthe medianof the two sorted arrays. The overall run time complexity should beO(log (m+n)).https://blog.csdn.net/qq_15711195/article/details/122888773LeetCode-540. Single Element in a Sorted Array [C++][Java]_贫道绝缘子的博客-CSDN博客You are given a sorted array consisting of only integers where every element appears exactly twice, except for one element which appears exactly once. Returnthe single element that appears only once.https://blog.csdn.net/qq_15711195/article/details/123034946LeetCode-81. Search in Rotated Sorted Array II [C++][Java]_贫道绝缘子的博客-CSDN博客There is an integer arraynumssorted in non-decreasing order (not necessarily withdistinctvalues). Given the arraynumsafterthe rotation and an integertarget, returntrueiftargetis innums, orfalseif it is not innums.https://blog.csdn.net/qq_15711195/article/details/123034345LeetCode-33. Search in Rotated Sorted Array [C++][Java]_贫道绝缘子的博客-CSDN博客There is an integer arraynumssorted in ascending order (withdistinctvalues). Given the arraynumsafterthe possible rotation and an integertarget, returnthe index oftargetif it is innums, or-1if it is not innums.https://blog.csdn.net/qq_15711195/article/details/123034586LeetCode-34. Find First and Last Position of Element in Sorted Array [C++][Java]_贫道绝缘子的博客-CSDN博客Given an array of integersnumssorted in non-decreasing order, find the starting and ending position of a giventargetvalue. Iftargetis not found in the array, return[-1, -1].https://blog.csdn.net/qq_15711195/article/details/123034091LeetCode-69. Sqrt(x) [C++][Java]_贫道绝缘子的博客-CSDN博客Given a non-negative integerx,compute and returnthe square root ofx. Since the return typeis an integer, the decimal digits aretruncated, and onlythe integer partof the resultis returned.https://blog.csdn.net/qq_15711195/article/details/123031582

你可能感兴趣的:(LeetCode刷题怪,leetcode,算法,职场和发展)