Created
January 15, 2017 17:24
-
-
Save deyindra/3d24c8d32b3bce6fbafe2ba1a0f340e4 to your computer and use it in GitHub Desktop.
Find Pivote of Sorted Array (Rotated or Non Rotated)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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