设为首页 - 加入收藏 焦点技术网
热搜:java
当前位置:首页 >

LeetCode Solutions : Search in Rotated Sorted Array II

导读:本文lviiii给大家介绍 LeetCode Solutions : Search in Rotated Sorted Array II。Follow up for "Search in Rotated Sorted Array":What if dupli。。。

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

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

Write a function to determine if a given target is in the array.


Java Solution ( refer to my blog LeetCode Solutions : Search in Rotated Sorted Array ):

public class Solution {    public boolean search(int[] A, int target) {  if(A.length==0)   return false;        int low=0;  int high=A.length-1;  while(low<=high){   int mid=low+(high-low)/2;   if(target==A[mid])    return true;   if(A[low]A[mid]){// the elements from mid to high is strictly increasing order     if(A[mid]
Of course, you are able to resolve it with the brute one, also need O(n)

(编辑: lviiii)

网友评论
相关文章