1 Bitwise XORSuitable for: interview, embedded development needs to save memory of the occasionSwap 2 variables without the help of an intermediate variableX=x+yY=x-yX=x-y1 #define_crt_secure_no_warnings2 3#include 4#include 5 6 Main ()7 {8UnsignedCharCH1 =Ten;9UnsignedCharCH2 = -;Ten Oneprintf"%d,%d\n", CH1, CH2); A -CH1 = ch1^CH2; -CH2 = ch2^ch1; theCH1 = ch1^CH2; - -printf"%d,%d\n", CH1, CH2); - +System"Pause"); -};Classical algorithm _ bit
??? Then we should take advantage of the next[0] we've got. Next[k-1] to beg for p[0] P[K-1] This substring is the largest of the same prefix , there may be classmates to ask-why ask p[0] P[K-1] The largest and the same prefix??? Oh, yes!Why is it?The reason is that p[k] has been mismatch with p[q] and p[q-k] P[q-1] again with p[0] P[k-1] The same, it seems p[0] P[K-1] So long the substring is not used, then I want to find a same also p[0] beginning, p[k-1] end of the substring that is p[0] P[
大位数 maxnum = arr[0] for x in arr: if x > maxnum: maxnum = x CNT = 0 while (maxnum! = 0) : maxnum/= Radix cnt + 1 return cntdef radixsort (arr,radix=10): k = cntdi Git (arr,radix) #获取最大位数 bucket = [[] for I in range (radix)] for I in range (1,k+1): For J in arr: #bucket [x] stores the number from low to high I bits X, in an array of 543,i=1 when there is bucket[3] bucket[j/(radix** (i-1))% (radix)].append (j)
The algorithm is described as follows: Quickly find out two numbers in an array, and let the sum of these two numbers equal to a given value. For the moment, I assume that all the integers in the array are unequal. This question I was asked in an interview, for various reasons, I did not answer up, very embarrassed. In fact, this problem is very simple, we use a relatively ingenious method to achieve the next. Note that elements that do not use a two-layer loop are traversed. The sample code is
Seven classical sorting algorithms based on python (recommended) and seven types of python
I. Basic concepts and classifications of sorting
Sorting is an operation that sorts a string of records in ascending or descending order based on the size of one or more keywords. Sorting algorithms are the methods for sorting records according to requirements.
Stability of sorting:
After sorting, if the sequence numbers of the two records are the same and the o
);}}} public void sort (int[] array) {createheap (array); sortHeap (array);} /** * Defragment the heap structure of a single node * @param array * Target array * @param nodeposition * node location */private void Sortnode (int[] Array, int nodeposition, int heapsize) {int leftchildpst = getleftchildposition (nodeposition); int rightchildpst = GetRigh Tchildposition (nodeposition); int largestposition = Nodeposition;if (Leftchildpst Finally, random pairs of arrays of length 100,000test a single
This is the same as the sword refers to the very classic question of the offer. The title is described as: Find the first occurrence of a character in a string. If you enter "Abaccdeff", Output ' B '. At first, the simplest way to think of it is to compare every character you visit with each character, and if you don't find the same element, it's the first character that appears once. This complexity is O (n^2). Obviously, this is not a high efficiency.The general direction of the problem is a
It is not difficult to find the common node of a linked list as a classic algorithm problem. What we need to know is that once the two linked lists have a common node, the shape of the two lists is a "Y" type. In other words, all nodes after the public node are the same. As follows:In fact, as long as the view of the picture, the implementation is very simple. First we traverse two linked lists, respectively, to derive their length l1,l2. Then, when looking for a common node, go ahead in the lon
forward one block /*The If section above is simplified as follows: if (left */ //loop from left to right, the pointer moves to find the first number greater than pivot while(Left pivot) { Left++; } if(Left //find the first number greater than pivotn[right--] = N[left];//fill this number in n[right] This position, right forward a grid//simplify with the same reasoning /*if (left */N[left]= pivot;//when exiting, I equals J, the pivot is filled in, the number is divided int
you talk about small later);Step Two: SMALL (IF ($A $: $A $9= $D $2,row ($2:$9), 10^10), row (1:1)): The function of the SMALL function is to return the minimum value of K, SAMLL ((2,3,5,9), row (1:1)), row (1:1) function for the selection of the K-small value;Step Three: Index (A:a,small (IF ($A $: $A $9= $D $2,row ($2:$9), 10^10), ROW (1:1)): The index function takes out the results that match the criteria and confirms by Shif+ctrl+enter
Grade
Class
Numb
a ring to deal with, in the array by counting 1, each found three no data area to fill in a count, straight and count up to 41, and then the array from index 1 to list, you can know each location of the suicide sequence, this is Joseph Permutation, 41 persons and a 3 of the appointment is as follows:14 36 1 38 15 2 24 30 3 16 34 4 25 17 5 40 31 6 18 26 7 37 19 8 35 27 9 20 32 10 41 21 11 28 39 12 22 33 13 29 23From the above, the last suicide is in the 31st position, and the penultimate suicide
one, the algorithm principleBubbling sorting is one of the switching sorts, by comparing the size of the adjacent two elements, and swapping the positions of the two elements if the order is found to be incorrect. When the first loop ends, the largest element is filtered out, then into the second loop, and so on, until there is no pair of data to Compare.Here's a case:Suppose there are 5 numbers, in Order: 5,4,6,3,1with the idea of bubbling sort. , the process is this:Outer first Loop:4,5,6,3,1
. Then there are two options:programme IThe fastest one will send the slowest 2 to the bridge.The first step: A and Z bridge, spend Z minutes.Step two: A back, spend a minute.Step three: A and Y bridge, spend y minutes.Fourth step: A back, spend a minute.The total number of these four steps is reduced by 2, which takes a + a + Y + z minutes.Scenario TwoThe fastest 2 will send the slowest 2 to the bridge.The first step: A and B bridge, spend B minutes.Step two: A back, spend a minute.Step three:
Hungarian nomenclature:By prefixing the variable name with the corresponding lowercase symbol, indicating the scope, type, etc. of the variable, followed by one or more word combinations, the word describes the purpose of the variable, such as I represents an integer and S represents a string.Example: var susername = ' Css8 '; var iCount = 0; Camel/Hump nomenclature mixed with uppercase and lowercase letters to form the name of the variable. Example: Var printloadtemplates;//the first letter of
******************************* /#include What is the complexity of five time complexity analysis? The length of the For loop in line 1th to 2nd takes the time θ (k). Line 3rd to 4th for Loop takes time to θ (n). The length of the For loop in line 6th to 7th takes the time θ (k). Line 9th to 11th for Loop takes time to θ (n). So the total time is theta (k+n). In practice, when the file K = O (n), we often use a count sort, when the run time is θ (n). Six features1. Advance must be known as the
This article has compiled a few Linux C language Classic interview questions, I believe that we better understand the C language under Linux will have a great help, welcome everyone to discuss correct.1. What is the output if you use the GCC compiler to execute the following programs under Linux?The answers are as follows:2, C language program does not use any condition operator, print out 10 times "Hello"?The answers are as follows:Or:3. What is the output if you use the GCC compiler to execute
JavaScript, which can be a data type, and then we can turn it into another data type, for example:
var a = "Code Carpenter";
Console.log (a); "Code Maker"
Console.log (typeof (a)); "String"
A = 123;
Console.log (a); 123
Console.log (a); "Number"
By observing the example above, the variable a starts out as a string type, and then a becomes a numeric type. So in JavaScript, where the data type requirements are not strict, there is little point in using the Hungarian nom
2017-08-13 19:31:47Writer:pprpAfter a general understanding of the KMP algorithm, although not deep enough, but already can write code, (can be said to be back)So this problem as a template, for everyone to use it.To give you a substring p and a main string s, how many substrings in the main string?The code is as follows: (I have marked the points to note, two functions can be used directly)#include #include#include#includeusing namespacestd;intans;Const intMAXN =1000005;intNEXT[MAXN];CharS[MAXN
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.