← 返回 uber 的题目列表Best Time to Buy and Sell Stock
类型:online_judge
Best Time to Buy and Sell Stock (Single Transaction)
You are given an integer array prices of length n, where prices[i] is the stock price on day i.
You may complete at most one transaction: choose one day to buy and a later day to sell (you must buy before you sell).
Return the maximum profit you can achieve; if no profit is possible, return 0.
Input Format
Line 1: an integer n, the length of the array
Line 2: n integers representing prices
Output Format
Print one integer: the maximum profit
Constraints
1 <= n <= 2 * 10^5
0 <= prices[i] <= 10^9
Examples (stdin -> stdout)
Example
Input
6
7 1 5 3 6 4
Output
5