Given an array of positive integers. All numbers occur even number of times except one number which occurs odd number of times. Find the number in O (n) Time constant space.Example:i/p = [1, 2, 3, 2, 3, 1, 3]o/p = 3A Simple solution are to run nested loops. The outer loop p
/*** Function: Some number of prime factor only 3, 5, 7, find the number of K.*/Two methods:Method One:/** * Idea: Multiply the numbers in the list with 3,5,7 to find the decimal places that are not yet added to the list. * Each time AI is added to the list, a temporary list is used to store 3ai,5ai and 7Ai. To generat
I went to interview an iPad development company the other day. The first question was to find a duplicate number in 1000 (1-999. The 1000 numbers are sequential and out of order. My first reaction is to create an array of 999, and then find the corresponding array subscript based on the number. If it is null, it is fil
PackageShuzu;/** Enter an array that has been sorted in ascending order and a number * Find two numbers in the array so that their sum is the number entered, requiring a time complexity of O (n) * If there are many pairs of numbers and equals the input number, the output can be any pair. */ Public classDemo1 {Private S
If there is a number in the array that appears more than half the length of the array, find this number. For example, enter an array of length 9 {1,2,3,2,2,2,5,4,2}. Since the number 2 appears in the array 5 times, which exceeds half the length of the array, the output is 2. #include If there is a
Problem: To determine the number of user input, or the value of a parameter of a method in a program, or whether the value of a variable is in a heap number.Concise notation: Put the heap number in the list, using the list's contains () method to check whether the list contains this number, reverse.The code is as follows: Static voidMain (string[] args) {Console.
Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=1394Understand the merger sort, learn a bit of other people's blog, have the topic to knock over ...This problem I use merge sort is I currently the fastest algorithm 62ms ... Of course, in my blog There are also wired and tree arrays to find the reverse number of the template;Here I do not discretization, but not all the reverse
Common:I am always used to call the common law, because I really can not find a proper name to describe it, in fact, is the simplest way, a little program based on the people are able to think, that is the SHIFT + count, very simple, not much to say, directly on the code, this method of operation of the number of input n is the highest bit 1 of theintBitcount (unsignedintN) {unsignedintc =0;//counter wh
Programmer = programming language basics + data structures + Algorithms
Over the past few days, I continue to return to the java basics and learn about the data structure. Here I will implement a simple algorithm-the algorithm for finding the number with the most appearance in the array
Public class HashMapTest1 {/*** find the number with the most numbers in an
Topic address
The main idea: S (n) is the sum of the true factors of n of positive integers, a factor that is less than n and divisible by n, such as S (12) =1+2+3+4+6=16. If any number m,s (m) is not equal to N, then it is said that N is a non-touch number, and that the number within 1000 is not a number.
To solve the
1, the following is the general method to find the prime number of 1~n:
The general method of finding the prime number of 1~n
#include
2, for the number of prime screening method, the specific method is not elaborated, Baidu can be found, simply say is to find a prime
Affinity number
Time limit:1000ms Memory limit:65536k have questions? Dot here ^_^
The topic describes if the factor of a and equals b,b factor and equals A, and a≠b, is called A, B is the affinity number pair. For example, the sum of all true approximations of 220 (i.e. not their own approximations) is: 1+2+4+5+10+11+20+22+44+55+110=284. 284 of all true approximate and for: 1+2+4+71+142=22
Label: A circle contains a finite number of vertices. A straight line does not pass through any point and equals all vertices.Consider this problem from outside the circle.Randomly find a straight line l that is separated from the circle, and then draw a straight line between each two points to mark the intersection with L (if parallel, ignore ), then start to rotate L with any unlabeled point on L as the c
#include First to find the maximum value, and then use the maximum value to go down to try to be at least two number of approximate, the method is to sift up the [BC] To find the number of any two number of conventions in the array, and to take maximum value in many case
Given an integer, outputs the number of 1 in the binary representation of this integer. For example, given an integer of 7, in which the binary is represented as 111, the output is 3.The problem can be done with bit operations.Idea: First, to determine whether the last digit of this number is 1, if 1, then the Counter plus 1, and then move right to discard the last one. Loop through the operation until the
to a group of numbers, only one number appears once, and all the other numbers are paired. Find out this number # include Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced."C" gives a group of numbers, only one number appears once, and all the other numbers appea
There is a 3*4 matrix that requires the program to find the value of the largest element in it, along with its line number and column number. (Daleitai algorithm)Solution: Program:#include int main (){int I, j, row = 0, Colum = 0, Max;int A[3][4] = {{1,2,3,4},{4,5,6,7},{-1,3,-5,10}};max = a[0][0];printf ("Array a:\n");for (i = 0; I {for (j = 0; J {printf ("%5d",
Only one number appears once in a set of data. All other numbers appear in pairs. Please find out the number. (using bit operations)Solution: Program:#include int Main (){int arr[] = {1,3,3,1,4,9,4,5,5};int i = 0;int len = sizeof (arr)/ sizeof (Arr[0]); for (i = 1; i {Arr[0] = arr[0] ^ arr[i]; //Put all the numbers in this set of digits to the bitwise OR, becaus
There is only one number in a set of data that appears once, and all the other numbers are paired, please find this number.(using bit operations)Use the XOR operation directly.The code is as follows:#include This article is from the "Materfer" blog, make sure to keep this source http://10741357.blog.51cto.com/10731357/1708445Only one
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.