Follow up for "Find Minimum in Rotated Sorted Array":
What if duplicates are allowed?

Would this affect the run-time complexity? How and why?

Suppose a sorted array is rotated at some pivot unknown to you beforehand.

(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).

Find the minimum element.

The array may contain duplicates.

 

由于可能存在相同元素,所以我们不能直接使用二分搜索法,如果左端和右端都是一样的元素的话我们无法在logn的复杂度下完成对下列情况的判断。

[9,9,9,1,9] [9,1,9,9,9]

,所以对本题用线性算法解决即可。

相关文章:

  • 2021-08-21
  • 2021-10-18
  • 2021-08-07
  • 2022-02-23
  • 2022-02-23
  • 2022-01-21
  • 2021-11-14
  • 2021-10-31
猜你喜欢
  • 2022-03-05
  • 2021-11-21
  • 2022-03-06
  • 2021-08-28
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案