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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

贫道绝缘子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值