← 返回 amazon 的题目列表Best Time to Buy and Sell Stock
类型:online_judge
Given an array prices where prices[i] represents the stock price on day i, find the maximum profit you can achieve. You may only buy on one day and sell on another day in the future. If no profit can be achieved, return 0.
Example:
Input: [7, 1, 5, 3, 6, 4]
Output: 5
Input: [7, 6, 4, 3, 1]
Output: 0
Constraints:
1 <= prices.length <= 10^5
0 <= prices[i] <= 10^4
Example
Input
[7, 1, 5, 3, 6, 4]