Leetcode_ input an array, target tree, check the target is the array subscript of which two of the sum, no repetition

Source: Internet
Author: User
Tags repetition

Today is the first day of Leetcode, but not very well. Do this, I can't believe

Original topic:

I give the answer:

1 classSolution {2  Public:3vector<int> Twosum (vector<int>& Nums,inttarget) {4vector<int>result;5          for(inti =0; I <nums.size (); i + +){6              for(intj = i+1; J <nums.size (); J + +){7                 if(Nums[i] + nums[j] = =target) {8 Result.push_back (i); The first thing to do is to pass the subscript of the computed array to a vector, failing9 Result.push_back (j);Ten                     returnresult; One                 } A                     -             } -         } the         returnresult; -     } -};
The first thing to do is to pass the subscript of the computed array to a vector, failing
Secondly, the computational complexity of this is particularly large and clearly does not conform to the standards required by the company.

Leetcode_ input an array, target tree, check the target is the array subscript of which two of the sum, no repetition

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.