Skip to content

Instantly share code, notes, and snippets.

@drewcassidy
Last active June 8, 2017 20:58
Show Gist options
  • Save drewcassidy/44d7e5d093a6aa8928318c917ea13de9 to your computer and use it in GitHub Desktop.
Save drewcassidy/44d7e5d093a6aa8928318c917ea13de9 to your computer and use it in GitHub Desktop.
stupid binary search for my AP Computer Science class in High School
public class BinarySearch {
public int find(int[] arr, int v) {
int i = 0;
int b = (1 << (Double.doubleToLongBits(arr.length - 1) >> 51));
while ((b >>>= 1) > 0) {
if ((i | b) < arr.length && arr[i | b] <= v) i |= b;
if (arr[i] == v) return i;
}
return -1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment