Best Time to Buy and Sell Stock
121 Best Time to Buy and Sell Stock
Related:Array && Dynamic Programming
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:I got array[7,1,5,3,6,4];The correct output should be 5;
解法一
1 |
|
解法二
[7,1,5,3,6,4]
1 |
|
一起回顾下max()方法
1 |
|
Best Time to Buy and Sell Stock
https://www.pengsifan.com/2018/12/10/BestTimeToBuyAndSellStock/