Last active
June 8, 2017 20:58
-
-
Save drewcassidy/44d7e5d093a6aa8928318c917ea13de9 to your computer and use it in GitHub Desktop.
stupid binary search for my AP Computer Science class in High School
This file contains 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
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