PAT [L2-016] may all lovers in the world be brothers and sisters who have been separated for many years (dfs super detailed explanation)
Original title
ha-ha. As we all know, intermarriage is not allowed within five clothes, that is, if the nearest common ancestor of two people is within five generations (i.e. myself, parents, grandparents, great grandparents and high grandparents), they cannot intermarry. Please help a couple to judge whether they can get married or not?
Inpu ...
Posted by rinteractive on Sat, 15 Jan 2022 05:17:13 +0100
Notes on data structure of postgraduate entrance examination - linear table
Chapter II linear table
2.1 outline requirements
(1) Basic concepts of linear table (2) Implementation of linear table 1. Sequential storage 2. Linked Storage (3) Application of linear table
2.2 basic concept of linear table
Definition of linear table: a linear table is a finite sequence of elements with the same charac ...
Posted by YOUAREtehSCENE on Sat, 15 Jan 2022 03:31:45 +0100
Sword finger OFFER brush notes Kaze-1
Data structure: linked list, queue, stack
JZ24 reverse linked list
Niuke network link Difficulty: simple
/*
struct ListNode {
int val;
struct ListNode *next;
ListNode(int x) :
val(x), next(NULL) {
}
};*/
class Solution {
public:
ListNode* ReverseList(ListNode* pHead) {
//The initialization part (initialization pointer p,pr ...
Posted by icaro on Sat, 15 Jan 2022 02:39:43 +0100
Linked list sorting problem
Problem expression
problem analysis
The problem itself is easy to understand. Here are two solutions. The key to the problem of the linked list is to pay attention to the pointing between nodes. In addition, pay attention to each node, such as virtual head node, current node, previous node, next node, etc. the memory distribution of the li ...
Posted by phprocky on Sat, 15 Jan 2022 01:42:07 +0100
[data structure and algorithm] in-depth analysis of the solution idea and algorithm example of "sum of three numbers"
1, Title Requirements
Give you an array num containing n integers. Judge whether there are three elements a, b and c in num, so that a + b + c = 0? Please find all triples with sum 0 and no repetition.Note: the answer cannot contain duplicate triples.Example 1:
Input: nums = [-1,0,1,2,-1,-4]
Output:[[-1,-1,2],[-1,0,1]]
Example 2:
Input: nu ...
Posted by bingo333 on Fri, 14 Jan 2022 22:33:25 +0100
java foundation - array
java foundation - array
Definition of array
An array is an ordered collection of the same data typeArray describes several data of the same type, which are arranged and combined in a certain orderAmong them, each data is called an array element, and each array element can access them through a subscript, starting from 0. expression:
int [] ...
Posted by Rushyo on Fri, 14 Jan 2022 22:20:36 +0100
380. Insert delete getRandom o time insert, delete and get random elements (Medium)
1. Description
Implement the RandomizedSet class:
RandomizedSet() Initializes the RandomizedSet object.bool insert(int val) Inserts an item val into the set if not present. Returns true if the item was not present, false otherwise.bool remove(int val) Removes an item val from the set if present. Returns true if the item was present, false o ...
Posted by aravona on Fri, 14 Jan 2022 18:41:41 +0100
Binary tree (linked list implementation) -- add, delete, change and query
Binary tree (linked list implementation)
1.1 basic definition of tree
Tree is a very important data structure in our computer. At the same time, using this data structure can describe many things in real life, such as genealogy, organizational structure of units, and so on.
A tree is a set with hierarchical relations composed of n (n > = ...
Posted by yarons on Fri, 14 Jan 2022 18:22:19 +0100
Algorithm and data structure 04 queue
queue
Queue is another special linear table. Its particularity is that queue only allows inserting data elements at the end of the table and deleting data elements at the header. It has the characteristics of first in, first out, then in and then out.We call the end that is allowed to be deleted as the front and the end that is inserted as the ...
Posted by ahzulfi on Fri, 14 Jan 2022 17:35:23 +0100
Red black tree -- c language implementation code
Red black tree
Red black tree is a binary lookup tree with color attribute for each node, either red or black. In addition to the mandatory General requirements for binary search trees, we have added the following additional requirements for any effective red black tree:
Nature 1 Nodes are red or black.
Nature 2 The root node ...
Posted by jfugate on Fri, 14 Jan 2022 09:35:30 +0100