# leetcode：121. Best Time to Buy and Sell Stock（Java）解答

Best Time to Buy and Sell Stock My Submissions Question

Say you have an array for which the ith element is the price of a given stock on day i.

If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), design an algorithm to find the maximum profit.

public int maxProfit(int[] prices) {
int maxPro = 0;
int minPrice = Integer.MAX_VALUE;
for (int price : prices) {
maxPro = Math.max(maxPro, price - minPrice);
minPrice = Math.min(minPrice, price);
}
return maxPro;
}

#### LeetCode(121)Best Time to Buy and Sell Stock

2014-01-21 02:39:12

#### 动态规划-121. Best Time to Buy and Sell Stock

2017-10-08 09:57:08

#### leetcode【121+122+123 best time to buy and sell stock】【python】

2016-09-12 21:04:35

#### [LeetCode] Best Time to Buy and Sell Stock IV

2015-02-23 00:08:34

#### Best Time to Buy and Sell Stock -- LeetCode

2014-04-09 05:33:32

#### 121. Best Time to Buy and Sell Stock [easy] (Python)

2016-05-28 01:02:17

#### Best Time to Buy and Sell Stock II -- LeetCode

2014-04-09 05:33:51

#### 关于LeetCode中Best Time to Buy and Sell Stock一题的理解

2016-09-09 13:55:36

#### Best Time to Buy and Sell Stock III -- LeetCode

2014-04-09 05:34:05

#### 【LeetCode】【Python题解】Best Time to Buy and Sell Stock II

2014-07-24 10:11:44