Leetcode Problem 121&122&123. Best Time to Buy and Sell Stock I/II/ III

Summer.K
4 min readNov 26, 2020

Problem 121:

Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), design an algorithm to find the maximum profit.Note that you cannot sell a stock before you buy one.

Example 1:

Input: [7,1,5,3,6,4]
Output: 5
Explanation: Buy on day 2 (price = 1) and sell…

--

--

Summer.K
0 Followers

Graduate student looking for data full-time job.