2022 Blue Bridge Cup learning - 7 greedy

Examples 1. Stock trading Title Description Given an array with length N, the ith number in the array represents the price of a given stock on day i. Design an algorithm to calculate the maximum profit you can make. You can complete as many transactions as possible (buying and selling a stock multiple times). Note: you cannot participate in ...

Posted by szms on Wed, 02 Feb 2022 05:33:14 +0100

Leetcode algorithm interview sprint stack and queue theory

Queue queue Deque pays attention to pronunciation. It is a data structure that can be accessed at both ends. If deque is used as a queue, some restrictions need to be made. One end can only enter and the other end can only exit. The queue learned yesterday is also OK. get is out and put is in. The difference between getting out of the q ...

Posted by mister_t101 on Wed, 02 Feb 2022 01:52:53 +0100

Three traversals of LeetCode 144 145 94 binary tree -- iterative method

Reference article 1 Reference article 2 Idea: Previously, we learned to use recursive method to traverse three kinds of binary trees. This time, we consider using iterative method to traverse and stack. It is recommended to read both reference articles. Among the two reference articles, the first one talks about how to use the iterative metho ...

Posted by amrigo on Tue, 01 Feb 2022 05:47:06 +0100

LeetCode brushes the power of question-3

Preface description Algorithm learning, daily problem brushing records. Topic connection Power of 3 Topic content Given an integer, write a function to determine whether it is a power of 3. If yes, return true; Otherwise, false is returned. The integer n is to the power of 3, which needs to be satisfied: there is an integer x so that n == ...

Posted by MoldRat on Mon, 31 Jan 2022 01:49:38 +0100

LeetCode132. Segmented palindrome string II - string dynamic programming

Topic overview Title Link: Ask me to do the problem Problem solution 1, General dynamic programming    in that sentence, the dynamic programming of string class can consider the state of the response problem of the first i characters, such as this problem and definition f ...

Posted by fred_belanger on Sun, 30 Jan 2022 23:46:04 +0100

LeetCode 207 curriculum (topological sorting) LeetCode 210 curriculum II

Title Description You must take numCourses this semester, marked 0 to numCourses - 1. Some prerequisite courses are required before taking some courses. The prerequisite courses are given by the array prerequisites, where prerequisites[i] = [ai, bi], which means that if you want to learn course ai, you must learn course bi first. For example, ...

Posted by toplay on Sun, 30 Jan 2022 22:11:03 +0100

Regular expression matching algorithm for problem solving

Title Description This topic comes from Force buckle , the difficulty is: difficulty, the title is described as follows: Give you a string s and a character rule p, please implement a support '.' Matches the regular expression of '*'. ‘.’ Match any single character'*' matches zero or more preceding elements The so-called mat ...

Posted by jkeppens on Sun, 30 Jan 2022 21:59:01 +0100

LeetCode1449. The sum of digit cost is the maximum number of target value (rethink the maximum sum in dynamic rules)

1449. The sum of digital costs is the maximum number of target values One question per day on June 12, 2021 Title Description Give you an array of integers cost And an integer target . Please return the maximum integer that can be obtained by satisfying the following rules: Add a digit to the current result( i + 1)The cost of is cost[i] (co ...

Posted by Defibber on Sun, 30 Jan 2022 20:10:55 +0100

Special topic solution of LeetBook linked list

Linked list Single linked list Design single linked list Note: it is not difficult to delete nodes in the middle and insert nodes in the middle, but header insertion or deletion should be considered when inserting or deleting nodes arbitrarily. It should be noted that if the head node changes, the head node will change. Therefore, when i ...

Posted by DragonFire-N[R] on Sun, 30 Jan 2022 18:08:50 +0100

Force buckle - minimum stack (Java implementation)

Topic content Design a stack that supports push, pop and top operations and can retrieve the smallest element in a constant time. push(x) -- push element x onto the stack.pop() -- delete the element at the top of the stack.top() -- get the stack top element.getMin() -- retrieves the smallest element in the stack. Example: Input: ["MinStack" ...

Posted by psycovic23 on Sun, 30 Jan 2022 13:16:12 +0100