Skip to content

Instantly share code, notes, and snippets.

@lifeparticle
Last active February 26, 2021 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lifeparticle/33326653ffd676179f7cf53d2de67f32 to your computer and use it in GitHub Desktop.
Save lifeparticle/33326653ffd676179f7cf53d2de67f32 to your computer and use it in GitHub Desktop.
public static int upperBound (int values[], int target) {
int left = 0;
int right = values.length - 1;
int mid;
if (values[right] <= target)
return values.length;
while (right > left){
mid = (left + right) / 2;
if(values[mid] <= target)
left = mid + 1;
else
right = mid;
}
return left;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment