本文共 334 字,大约阅读时间需要 1 分钟。
class Solution {public: int searchInsert(int A[], int n, int target) { // Start typing your C/C++ solution below // DO NOT write int main() function int l = 0; int r = n-1; while (l <= r) { int mid = l+(r-l)/2; if (A[mid] > target) r = mid-1; else if (A[mid] < target) l = mid+1; else return mid; } return l; }};
转载地址:http://vqxti.baihongyu.com/