//arr数组升序 //n是数组长度,也就是l r正好是数组的左右的第一个和最后一个 int l = 0, r = n - 1; int mid; while(l <= r){ mid = (l + r) / 2; if(arr[mid] == target) return mid; else if(arr[mid] > target) r = mid - 1; else l = mid + 1; }
标签:二分,int,mid,查找,数组,模板 From: https://www.cnblogs.com/sunjianzhao/p/16726095.html