← 返回 amazon 的题目列表Best Time to Buy and Sell Stock
类型:online_judge
Given an integer array where each element represents the price of a stock on a particular day, design an algorithm to calculate the maximum profit you can achieve. You can complete at most one transaction (i.e., buy and sell one stock). Please note that you cannot sell a stock before you buy one.
Input Description:
An integer array prices, representing the stock price on each day.
Output Description:
Return an integer, which is the best profit value.
Sample Input:
[7, 1, 5, 3, 6, 4]
Sample Output:
5
Constraints:
1 <= prices.length <= 10^5
0 <= prices[i] <= 10^4
Example
Input
[7, 1, 5, 3, 6, 4]