LeetCode 138 -- copy linked list with random pointer

1. topic 2. answers When traversing the list for the first time, copy the node values of the old list to create a new list, and define an unordered map as the hash table. The key of the hash table is the node pointer of the old list and the value is the node pointer of the new list. Then, traverse the list for the second time, access the rando ...

Posted by atravotum on Sat, 07 Dec 2019 08:42:06 -0800

C + + language -- implementation of sequence table, using the method of dynamic array

Some common things in C + +, through the use of dynamic array to achieve the order table, Have mastered the following knowledge points: 1. There are three methods of pretreatment Macro definition, file inclusion, conditional compilation 2. When using a variable with the same name, you can use the namespace class in the outer layer to solve ...

Posted by bradley252 on Sat, 07 Dec 2019 08:31:59 -0800

#leetcode's way to brush questions 31 - next permutation

To achieve the function of getting the next permutation, the algorithm needs to rearrange the given number sequence into the next larger permutation in the dictionary order.If the next larger arrangement does not exist, rearrange the numbers into the smallest (i.e., ascending) arrangement.It must be modified in place and only additional constan ...

Posted by Renich on Sat, 07 Dec 2019 06:32:04 -0800

Find such two data: 5 digits = 2 * 4 digits, 9 digits are different

First, write to judge whether a five digit number and a four digit number are the sameUsing the method of mark array to judgeReturn 1 if different, return 0 if same int panbie(int x, int y) { int i, m, n; int a[10] = { 0 };//Define tag array for (i = 0; i <= 4; i++) { n= x % 10; a[n]++;//Array marking ...

Posted by tha_mink on Fri, 06 Dec 2019 14:20:57 -0800

[C + +] 31 perfect complex class

Perfect complex class Operation that complex class should have Operation: +, -, */ Comparison: = == Assignment: = Modulus: modulus Using operator overloading Unified operation of complex number and real number The comparison of unified complex number and real number Complex operator + (const Complex& c); Complex operator - (const C ...

Posted by Intelly XAD on Fri, 06 Dec 2019 13:43:57 -0800

C + + calls functions in Python scripts

1. Environment configuration After installing python, copy the include and lib of Python to your own project directory And then include it in the project   2. examples Write a python test script first, as follows In this script, two functions are defined: Hello() and_add(). The file name of my script is mytest.py C++ Code: #incl ...

Posted by jini01 on Fri, 06 Dec 2019 12:43:08 -0800

#leetcode: the way to brush questions

A list is given. Each k nodes are flipped and the flipped list is returned.k is a positive integer whose value is less than or equal to the length of the list. If the total number of nodes is not an integral multiple of k, the remaining nodes will remain in the original order. Example:Given this list: 1 - > 2 - > 3 - > 4 - > 5When ...

Posted by Spekta on Thu, 05 Dec 2019 14:03:57 -0800

Solution to the problem of Luogu: P1209 [[USACO1.3] Barn Repair]

Original question portal: https://www.luogu.org/problemnew/show/P1209 First of all, this is a greedy problem.  Let's first analyze its greedy strategy.  For example:4 50 18  3 4 6 8 1415 16 17 2125 26 27 30 31 40 41 42 43  The difference between them is:1 2 2 6 1 1 1 4 4 1 1 3 1 9 1 1 1  Since we want to minimize the length of the b ...

Posted by nadz on Thu, 05 Dec 2019 12:26:50 -0800

LeetCode 98 -- verify binary search tree

1. topic 2. answers For a node, there are four situations: The node is empty or both left and right nodes of the node are empty; Only the right node is empty; Only the left node is empty; Left and right nodes are not empty; If the left and right sub nodes of the current node satisfy the condition of binary search tree, we can recursively jud ...

Posted by jpearson on Wed, 04 Dec 2019 17:51:31 -0800

LeetCode 109 -- Transformation of ordered list into binary search tree

1. topic 2. answers 2.1. Method I stay LeetCode 108 -- transform an ordered array into a binary search tree In, we have implemented the transformation of ordered arrays into binary search trees. Therefore, here, we can first traverse the linked list, store the data of the nodes into an ordered array, and then convert the ordered array into a b ...

Posted by shlumph on Wed, 04 Dec 2019 16:16:38 -0800