 # LEETCODE -121- The best time to buy or sell stocks

Given an array of prices, the ith element of prices[I] represents the price of a given stock on day I. You can only buy the stock on a certain day and sell it on a different date in the future. Design an algorithm to calculate the maximum profit you can make. Return the maximum profit you can make from the transaction. If you can't make any profit, return 0. For an example, see Leetcode...

# [Algorithm] DP steel bar cutting problem

The four steps of DP describe the structural characteristics of an optimal solution. Recursively define the value of the optimal solution. Calculate the value of the optimal solution, usually using the bottom-up method. Using the calculated information, an optimal solution is constructed. The first three steps are the basis for solving DP. If you only need the value of an optimal solution, but not the solution itself, you can ignore Step 4. If a fourth step is required, it is sometimes necessary to maintain some additional information during the execution of step 3 in order to construct an optimal solution. Steel bar cutting example scenario: put...

# 【 Algorithm 】 The longest common substring

Solution: if the character is same to 1, otherwise set to 0 to reduce repeated calculation, arr [I] [j] = arr [I - 1] , the point to note here is when I = = 0 | | j = = 0 to set values directly.

# Fall mother to deny? An air mass out of 6 stock algorithms to pump

I want to clear my stock and go home, but I fear that I may soon rebound and be overwhelmed. Instead of saving negative interest, it is better to muddle between, less chase up, do not kill down, sleep at night, should not hate, profit always in the unintentional. The month has rain or shine round lack, the stock has a horizontal rise and fall, the matter is difficult to complete. This article has been included in the front canteen of the same name warehouse Github github.com/Geekhyt, welcome to the canteen, if you think the food and wine is still delicious, a Star for the canteen owner is mo...

# ARTS - 21 LeetCode 322 change for classic learning materials | distributed system

Each week, I will write an Arts: Algorithm, Review an English article, Technique/Tips, Share a small Technique and Share an idea.

# LeetCode801. The minimum number of swaps to increment a sequence

I don't know if you're going to do the same thing as me, but in my original proposal, I only thought about A[I] &gt;; A[i-1] &amp;amp; &amp;amp; B[i]&amp;gt; If the condition B[i-1] is satisfied, the element in position I will not be exchanged; otherwise, the element in position I will be exchanged. This scheme is relatively simple, and then consider the conditions are not comprehensive, we will give an example to explain; Here's a look at this version of the code

# 0/1 knapsack, LCS, LIS

Many years ago , In Teddy's hometown there was a man who was called "Bone Collector". This man like to collect clocks and ranges of bones. Such as dog's, cow's, also he went to the grave... The bone collector had a big bag with a volume of V ,and along his trip of collecting there are a lot of bones , obvi...

# Number of towers - classic example

I have told you, this is a DP topic, can you AC? Input data begins with an integer C, representing the number of test instances, and the first line of each test instance is an integer N(1 &amp;lt; = N &amp;lt; = 100), denotes the height of the tower, and then denotes the tower with N rows of numbers, where row I has I integers, and all integers are within the interval [0,99]. For each test instance, the Output is the maximum possible sum. For each test instance, the Output is...

# Dynamic programming - algorithm introduction

Dynamic Programming (DP for short) is a method used in mathematics, management science, computer science, economics and bioinformatics to solve complex problems by decomposing the original problem into relatively simple sub-problems. Dynamic programming is often applied to problems with overlapping subproblems and optimal substructure, and the time of dynamic programming is often much less than that of the naive method. The basic idea behind dynamic programming is simple...

# What is the pressure DP? This solution will get you started

Title Address (464. Can I Win) [Link] Title Description {Code... } The function signature of the problem is as follows: {code... } gives you two integers, maxChoosableInteger and desiredTotal, and lets you return a Boolean value. Two Special Cases Let's first consider the two special cases. All of the following solutions apply to both of these special cases and therefore will not be repeated. If d...

Search