Skip to content

Instantly share code, notes, and snippets.

@liushapku
Created December 13, 2018 08:48
Show Gist options
  • Save liushapku/a658c2d76adbf515bacf0052eb389152 to your computer and use it in GitHub Desktop.
Save liushapku/a658c2d76adbf515bacf0052eb389152 to your computer and use it in GitHub Desktop.
searchsorted(arr, x, 'left') returns the position i such that arr[i-1] < x <= arr[i],
so that i is the first one such that x <= arr[i]. Equivalent to lower_bound in c++

searchsorted(arr, x, 'right') returns the position i such that arr[i-1] <= x < arr[i],
so that i is the first one such that x < arr[i]. Equivalent to upper_bound in c++
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment