Skip to content

Instantly share code, notes, and snippets.

@andriybuday
Created February 2, 2020 20:11
Show Gist options
  • Save andriybuday/925f0252f98f2126d68b3d86ec11eaad to your computer and use it in GitHub Desktop.
Save andriybuday/925f0252f98f2126d68b3d86ec11eaad to your computer and use it in GitHub Desktop.
binary search
int i = 0, j = n-1;
while(i <= j) {
int m = i + (j-i) / 2;
if(arr[m] == target) {
return m;
} else if(arr[m] < target) {
i = m+1;
} else {
j = m-1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment