5.在一个有序数组中,找>=某个数最左侧的位置(二分法)

int BSLeft(int arr[], int size, int target)
{
  if (!arr) return;
  int Left = 0;
  int Right = size-1;
  int Mid = 0;
  int Index = -1;
    
  while (Left < Right)
  {
    Mid = Left + ((Right-Left)>>1)
    if (arr[Mid] >= target)
    {
       Index = Mid;
       Right = Mid - 1;
    }
    else
    {
        Left = Mid + 1;
    }
  }
    return Index;
}
posted @ 2022-09-08 11:05  test369  阅读(57)  评论(0编辑  收藏  举报