zoukankan      html  css  js  c++  java
  • leetcode Search Insert Position

    代码:

     1 #include<iostream>
     2 
     3 using namespace std;
     4 
     5 int searchInsert(int A[], int n, int target) {
     6     int l = 0;
     7     int r = n - 1;
     8     while (l <= r){
     9         int mid = (l + r) / 2;
    10         if (target < A[mid]){
    11             r = mid - 1;
    12         }
    13         else if (target > A[mid]){
    14             l = mid + 1;
    15         }
    16         else{
    17             return mid;
    18         }
    19     }
    20 
    21     return r + 1;
    22 }
    23 
    24 int main(){
    25     int A[] = {1};
    26     cout << searchInsert(A, 1, 2) << endl;
    27 }
  • 相关阅读:
    UI
    OC之block
    web前端开发学习
    OC面向对象下之文件
    UIButton
    视图
    frame和bounds
    UIView
    UIWindow
    Hello friends!
  • 原文地址:https://www.cnblogs.com/chaiwentao/p/4451052.html
Copyright © 2011-2022 走看看