[My C language interview series] 012 find the second largest number in the integer Array
Find the second largest number in the integer Array
Question: Write a function to find the second largest number in an integer array. [
Find the maximum number of time limits: +Ms | Memory Limit:65535KB Difficulty:2
Describe
Delete the M numbers in the integer n so that the remaining digits are the largest of the new numbers in the original order,
For example, when n=92081346718538,m=10, the new maximum number is 9888.
Input
#include
--------------------------------------------------------------------------------------------------------------- -------------------------------------
There is a better solution: "The beauty of programming" reading notes-"to find the number of binary 1"
http://blog.csdn.net/justpub/article/details/2292823
The beauty of programming--Microsoft technical interview experience, reading notes
"
Looking for the maximum number of K in an array, we will first talk about a very simple method, using the segmentation algorithm in quick sorting, that is, we often see the partition. This function returns a value of the int type. This value represents the split point between the first half of the number and the last half of the number. The first half of the
A+b AgainAccepted:15 submit:243Time limit:1000 MS Memory limit:65536 KBTitle DescriptionLast fun Sai Xiaoming a+b pit A lot of students do not like to think, Xiao Ming in order to apologize, this time out a simple a+b to everyone when check-in questions, I hope we can be happy brush questions. So, the problem comes!!!The value of the smallest positive integer x that makes B/(a+x) an integer.InputThe first line is an integer K (k≤10000) that represents the nu
] = A [0];
B [0] [1] = 1;
Int t = 0;
Bool notExist = true;
For (int I = 1; I
{
For (int j = 0; j
{
If (A [I] = B [j] [0])
{
B [j] [1] ++;
NotExist = false;
Break;
}
}
If (notExist)
{
B [t ++] [0] = A [I];
}
}
Int max = 1;
Int k = 0;
For (int I = 0; I
{
If (B [I] [1]> max)
{
Max = B [I] [1];
K = I;
}
}
TheOne = B [k] [0];
}
Method 2Sort the array. The number in the middle is the number you are looking.If
Find out which process is consuming commands for a port number1) Use the lsof commandLsof is a very powerful Linux tool that she is used to find out which programs use those files. Under the Linux system, basically everything can be used as a file. The socket is, of course, a file. So lsof can be used to find out who used a certain port. Specific methods:lsof-i:p
Describe:
Title DescriptionPlease find the longest consecutive number string in the string, and return the length of the string, and if there is a continuous number string with the same length, the last consecutive number string is returned;Note: The number string only n
(Hdu step 2.1.6) find new friends (simple use of the Euler's function: calculate the number of elements that are mutually compatible with n), hdu2.1.6
Question:
Find new friends
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission (s): 2788 Accepted Submission (s): 1307
Pr
Hdu1029:ignatius and the Princess IVKuangbin Topic 12 Basic DP:B problemTime limit:2000/1000 MS (java/others) Memory limit:65536/32767 K (java/others)Total submission (s): 35107 Accepted Submission (s): 15340Problem Description "OK, you aren't too bad, em ... But can never pass the next test. "Feng5166 says."I'll tell you a odd number N, and then N integers. There'll be a special integer among them and you've to tell me which an integer is the Special
This also lets us find the number of duplicates in the array, but gives a lot of restrictions. In fact, Leetcode seems to some restrictions on conditions, can not make judgments, we are still strict requirements of the good OH.
First of all, the first one can not change the array, in fact, this is to limit our sort, if the sort, and then iterate again quickly can find
Find out the number of isomorphic numbers between 1 and N. A homogeneous number is a group of numbers: it appears to the right of the square number. For example: 5 is the number to the right of 25, 25 is 625 to the right, and 5 and 25 are isomorphic numbers.
Detailed De
1. The easiest way to thinkWe can use the simplest way to find an array of arbitrary size of the number, that is, according to a sort of array of all the elements of the order, and then as needed to remove it, the knowledge of this way of time complexity and space complexity is relatively large, so, with the following way2. By setting two variables to make a judgmentThis way you can
Title Description: http://ac.jobdu.com/problem.php?pid=1371Enter n integers to find the smallest number of K. For example, enter 4,5,1,6,2,7,3,8 these 8 numbers, then the smallest 4 number is 1,2,3,4,.The first way of thinking:As in the previous question, using the division function in the quick sort, the dividing element is the final subscript index less than k,
One, the problem descriptionSuppose that given an ordered array of integers arr, and an integer k, Q K appears in the array several times?Second, solve the ideaThe ① array is ordered, so you can consider using two points to find② If you can find the index position of the first occurrence of K in the array first_index and the last occurrence of the index position Last_indexWe can know the
q, int a1[], long long int number) {if (P Three: tree-like arrayThe tree array solution is very difficult to understand, I have not understood, do not need to understand. Here is a code on the Internet:#include since the previous article Blog we know that any tree-like array can solve the problem, line tree can be solved, why not use line tree to solve it? Four: line segment treeThe idea of n Span style= "Color:rgb (54,46,43)", elements are also
Turn from: http://blog.csdn.net/newhappy2008/article/details/6857098
Question: There are n+2 number, n number appeared even several times, 2 numbers appear odd several times (these two numbers are not equal), ask the space complexity of O (1), find out these two numbers, do not need to know the exact location, just need to know these two values.Solution: If only
Given a binary array, find the maximum number of consecutive 1s in this array.Example 1:Input: [1,1,0,1,1,1] Output: 3Explanation: the first and digits or the last three digits is consecutive 1s. The maximum number of consecutive 1s is 3.note:
The input array would be only contain and 0 1 .
The length of input array is a positive integer and wou
# Pragma once # include
# Include "moonmath. H" # include
// Prime digit replacements // problem 51 // by replacing the 1st digit of * 3, it turns out that six of the nine possible values: 13, 23, 43, 53, 73, and 83, are all prime. /// by replacing the 3rd and 4th digits of 56 ** 3 with the same digit, this 5-digit number is the first example having seven Primes among the ten generated numbers, yielding the family: 56003,561 13, 56333,564 43, 566
There is a set of numbers, which reduce the number from 1 to n, and the order is also disordered. Put it in a n-1 array. Please find the missing number.
Use 1 + 2 +... + N (that is, n (n + 1)/2) to subtract the sum of the current input data. The time complexity is O (n), and the space complexity is O (1). The disadvantage is that it is easy to overflow. T
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.