Skip to content

Instantly share code, notes, and snippets.

@ashkrit
Created April 8, 2016 15:48
Show Gist options
  • Select an option

  • Save ashkrit/c92620b3506abe6776169a0e8cc6834a to your computer and use it in GitHub Desktop.

Select an option

Save ashkrit/c92620b3506abe6776169a0e8cc6834a to your computer and use it in GitHub Desktop.
static int rotationPoint(char[] values) {
int start = 0;
int end = values.length - 1;
char startCharacter = values[0];
while (start <= end) {
int mid = (start + end) >>> 1;
if (isRotationPoint(values, mid)) {
return mid;
} else if (values[mid] > startCharacter) {
start = mid + 1;
} else if (values[mid] < startCharacter) {
end = mid - 1;
}
}
return -1;
}
static boolean isRotationPoint(char[] values, int mid) {
return values[mid - 1] > values[mid] && values[mid + 1] > values[mid];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment