Skip to content

Instantly share code, notes, and snippets.

@deyindra
Created January 15, 2017 17:24
Show Gist options
  • Save deyindra/3d24c8d32b3bce6fbafe2ba1a0f340e4 to your computer and use it in GitHub Desktop.
Save deyindra/3d24c8d32b3bce6fbafe2ba1a0f340e4 to your computer and use it in GitHub Desktop.
Find Pivote of Sorted Array (Rotated or Non Rotated)
//O(log(N)) complexity
public <T extends Comparable<T>> static in findPivote(T[] array){
int low = 0;
int hight = array.length - 1;
while(array[low].compareTo(array[high])>0){
int mid = low + (high -low)/2;
if(array[mid].compareTo(array[high])>0){
low = mid + 1;
}else{
high = mid;
}
}
return low;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment