378. The K-th smallest element in the ordered matrix & & 373 Find and minimum K-pair numbers (multiple merge priority queue ๐ž“œ binary search)

Link: https://leetcode-cn.com/problems/kth-smallest-element-in-a-sorted-matrix/ subject Give you a n x n matrix, where the elements of each row and column are sorted in ascending order to find the k-smallest element in the matrix. Note that it is the k-th smallest element after sorting, not the k-th different element. Use case Example 1: Input ...

Posted by tapos on Sat, 15 Jan 2022 05:04:56 +0100

python3__leecode/1743. Restore arrays from adjacent element pairs

1, Brush question content Original question link https://leetcode-cn.com/problems/restore-the-array-from-adjacent-pairs/ Content description There is an integer array nums composed of n different elements, but you can't remember the specific content. Fortunately, you still remember each pair of adjacent elements in num. Give you a two- ...

Posted by artweb on Sat, 15 Jan 2022 04:41:30 +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

LeetCode tree review II

236. Nearest common ancestor of fork tree Given a binary tree, find the nearest common ancestor of two specified nodes in the tree. Baidu Encyclopedia defines the nearest public ancestor as: "for two nodes p and q with root tree T, the nearest public ancestor is expressed as a node x, which satisfies that x is the ancestor of p and q, an ...

Posted by bouba on Fri, 14 Jan 2022 22:43:00 +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

leetcode 918 ring maximum subsequence sum

Unlike the sum of the largest subsequences of an ordinary array, one state transition equation can solve all the problems. The ring subsequence increases the possibility of more optimal values, such as sequence [5, - 3, 5]. If the former, the maximum value is 7. If the front and rear end sequences can be connected, the maximum value should be 1 ...

Posted by bickyz on Fri, 14 Jan 2022 20:10:51 +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

Algorithm: maximum compatibility score backtracking vs KM

This question comes from the third question of the 251th round of force deduction competition. The difficulty is medium. Investigate the backtracking method or KM algorithm Title: maximum compatibility score There is a questionnaire composed of n questions. The answer to each question is either 0 (no), or 1 (yes). The questionnaire was dis ...

Posted by cdorob on Fri, 14 Jan 2022 07:17:54 +0100

Sword finger Offer II 048 Serialization and deserialization binary tree

Serialization is the operation of converting a data structure or object into continuous bits, and then the converted data can be stored in a file or memory. At the same time, it can also be transmitted to another computer environment through the network, and the original data can be reconstructed in the opposite way. Please design an algorithm ...

Posted by refined on Fri, 14 Jan 2022 06:05:01 +0100

[LeetCode skimming - data structure]

2022 winter vacation LeetCode question brushing - task 01: linked list Introduction: the author is basically Xiaobai, so this topic brushing meeting is a difficult process. At the same time, it is also through this team learning to pick up the previous knowledge, and more importantly, it is to expand and consolidate. Therefore, this blog may b ...

Posted by cmason22 on Thu, 13 Jan 2022 17:00:00 +0100