Summary of leetcode problem solving methods

1. Sliding window method Example: 209. Minimum length subarray (find the smallest array satisfying > = target) Idea: use two pointers (similar to fast and slow pointers). If you are not satisfied, move the r pointer to the right until you are satisfied. If you are satisfied, move the l pointer to the left until you are not satisfied. Meth ...

Added by erasam on Thu, 10 Mar 2022 10:28:18 +0200

Leetcode problem solving algorithm greedy algorithm (python version)

1. The longest chain that a number pair can form 646. Longest number pair chain (Medium) Method 1: greedy algorithm Sort all pairs according to the size of the second number. The first step is to select the pair with the smallest ending number. Then, each step selects the number that does not conflict with the last selected number pair and ...

Added by zaiber on Thu, 10 Mar 2022 02:07:41 +0200

Divide and conquer, mathematical problems and bit operations

1, Divide and conquer method of reducing complexity to simplicity 1. Design priority for arithmetic expressions Question: Give you a string expression composed of numbers and operators, combine numbers and operators according to different priorities, calculate and return the results of all possible combinations. You can return answers in any or ...

Added by diex on Wed, 09 Mar 2022 04:32:56 +0200

Dichotomy -- it will be abolished as soon as you look at it

1, What is dichotomy? Dichotomy, also known as binary search, is generally used to find the position of a value in an ordered array or the insertion position of a given specific value; Compared with the O (n) complexity of traversing the entire array once, binary search can reduce the complexity to o (logn); The basic concept of bisectio ...

Added by vtb on Tue, 08 Mar 2022 22:55:58 +0200

1807 replace parentheses in string

Title Description: Give you a string s, which contains pairs of parentheses, each containing a non empty key. For example, in the string "(name) is (age) yearsolve", there are two pairs of parentheses, which contain the keys "name" and "age" respectively. You know the values corresponding to many keys. These relati ...

Added by jorgep on Tue, 08 Mar 2022 22:08:39 +0200

Force buckle LCP37 - Minimum rectangular area

Note: Question 5 of 2021 force buckle cup spring team competition Key points of algorithm: Intersection of two linesDivide barrels by slopeDetail processing subject Title Link LCP 37. Minimum rectangular area Title Description There are NN straight lines on the two-dimensional plane in the form of y = kx + b, where K and B are integer ...

Added by mariolopes on Tue, 08 Mar 2022 21:23:05 +0200

LeetCode daily question solution: 2055 Plates between Candles - problem solving - python && C + + source code

Here is a long table with plates and candles lined up on it. Give you a string s with subscript starting from 0 |, which contains only the characters' * 'and' | ', where' * 'represents a plate and' | 'represents a candle. At the same time, you will be given a two-dimensional integer array {queries with subscript starting from 0}, where {querie ...

Added by karikamiya on Tue, 08 Mar 2022 11:30:18 +0200

dfs pruning and iterative deepening and bidirectional dfs

1, Question sequence: 1. Consider how to correctly search out all schemes 2. Consider pruning again 1. Optimize search order In most cases, we should give priority to searching nodes with fewer branches. 2. Eliminate equivalent redundancy For example, if the order is not considered, search by combination 3. Feasibility pruning If a scheme is i ...

Added by lhaynes on Tue, 08 Mar 2022 06:57:00 +0200

Codeforces round #772 (Div. 2)

Source code: ACM/OpenjudgeNow/Codeforces at master · abmcar/ACM (github.com) Better reading experience: Jump coordinate A. Min Or Sum Main idea of the title: Idea: A + b > = a | B, we can replace a and B with 0,a|b. in this form, finally, we can replace the array with several zeros and an array | and The final sum is the array | an ...

Added by haydndup on Tue, 08 Mar 2022 05:08:28 +0200

Leetcode[300. Implement Trie] - prefix tree

Leetcode[300. Implement Trie] - prefix tree Title: Trie (pronounced like "try") or prefix tree is a tree data structure used to efficiently store and retrieve keys in string data sets. This data structure has many application scenarios, such as automatic completion and spell checking. Please implement the Trie class: Trie() Initia ...

Added by ignite on Mon, 07 Mar 2022 22:13:56 +0200