← 返回 oracle 的题目列表Best Time to Buy and Sell Stock (One Transaction)
类型:online_judge
Given an integer array prices, where prices[i] is the stock price on day i, make at most one transaction: buy on one day and sell on a later day.
Return the maximum profit possible. Return 0 if no profitable transaction exists.
Input
Line 1: integer n
Line 2: n integers representing prices
Output
One integer: 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