← 返回 oracle 的题目列表Best Time to Buy and Sell Stock
类型:online_judge
Given an array prices, where prices[i] is the price of a stock on day i, you may complete at most one transaction: buy on one day and sell on a later day.
Return the maximum profit. Return 0 if no profitable transaction exists.
Input Format
First line: integer n
Second line: n daily prices
Output Format
Print the maximum profit.
Constraints
1 <= n <= 2 * 10^5
0 <= prices[i] <= 10^9
Example
Input
6
7 1 5 3 6 4
Output
5