A Tencent front-end question mainly about Algorithms

Source: Internet
Author: User

Question: there is a set of numbers, from 1 to n (assuming n = 10000), from the arbitrary deletion of the three numbers, the order is also disrupted, the remaining number in an array of n-3, find the missing number, which requires faster algorithms.

The question is the front-end, but it is actually an algorithm question. Below is a relatively fast algorithm, which is said to be used in programming Pearl River.

Int _ tmain (INT argc, _ tchar * argv []) {int aold [] = {5, 1, 3, 0, 9, 2, 7, 8 int * anew = new int [11]; // actually, the subscript of an existing number is used for (INT I = 0; I <7; I ++) {int temp = aold [I]; anew [aold [I] = 1;} int * Alost = new int [3]; int K = 0; for (Int J = 0; j <11; j ++) {int IIi = anew [J]; If (anew [J]! = 1) {Alost [k] = J; k ++ ;}}

If (null! = Anew)
{
Delete anew;
Delete Alost;
Anew = NULL;
Alost = NULL;
}
) Return 0 ;}

 

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.