Leetcode Search Insert Position binary search (two sub-subscript)

Source: Internet
Author: User

One of the basic problems is to mingle in the foundation of a variety of problems, sometimes in small companies to see the big questions, but more is seen in the choice of questions ...

Test instructions: In an ordered series, insert a number of target to find the insertion position.

Landlord here to update the "two-point search review" the first problem of the solution, more similar, of course, is temporarily written today.

Know this problem completed the second Leetcode 4 of the two-point notation, landlord lazy ...

1 classSolution {2  Public:3     intSearchinsert (vector<int>& Nums,inttarget) {4         intL =0, r = nums.size ()-1;5          while(L <=R) {6             intMID = L + (r-l)/2;7             if(Nums[mid] <target) {8L = mid +1;9             }Ten             ElseR = Mid-1; One         } A         returnl; -     } -};

Here gives the landlord at that time a problem solution, please do not despise landlord ...

 1  class   solution { 2  public  :  3  int  >& nums, int   target) {  4  vector< Lower_bound (Nums.begin (), Nums.end (), target);  5   Nums.begin ();  6   7  };

Yes, again the library function ^_^

Leetcode Search Insert Position binary search (two sub-subscript)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.