标签:style color io java ar for div sp cti
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.
public class Solution { public boolean search(int[] A, int target) { if(A==null) { return false; } int left=0; int right=A.length-1; int middle; while(left<=right) { middle=left+(right-left)/2; if(A[middle]==target) { return true; } if(A[left]==A[right]) { left++; continue; } if(A[left]<=A[middle]) { if(A[left]<=target&&target<=A[middle]) { right=middle-1; } else { left=middle+1; } } else { if(A[middle]<target&&target<=A[right]) { left=middle+1; } else { right=middle-1; } } } return false; } }
Search in Rotated Sorted Array II
标签:style color io java ar for div sp cti
原文地址:http://blog.csdn.net/jiewuyou/article/details/39369539