Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public int findMinInSortedArray(int[] a)
- {
- int n=a.length;
- int low=0, high = n -1, mid, next, previous;
- while(low<=high)
- {
- if(a[low]<a[high])
- return a[low];
- mid=(low+high)/2;
- next = (mid+1)%n; previous = (mid-1+n)%n;
- if(a[low] >= a[mid] && a[previous] >= a[mid])
- return a[mid];
- if(a[mid] <= a[high])
- high = mid-1;
- else low=mid+1;
- }
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement