# [LeetCode] Best Time to Buy and Sell Stock(Java)

<span style="font-size:24px;">public class Solution {
public int maxProfit(int[] prices) {
if(prices.length == 0)
return 0;
int[] minA = new int[prices.length];
minA[0] = prices[0];
int i = 1,max = 0,temp = 0;
while(i<minA.length){
if(prices[i]<minA[i-1])
minA[i] = prices[i];
else
minA[i] = minA[i-1];
temp = prices[i] - minA[i];
if(temp > max)
max = temp;
i++;
}
return max;
}
}</span>

2016/8/30

• 本文已收录于以下专栏：

## Best Time to Buy and Sell Stock

Best Time to Buy and Sell Stock 本题有一共有四中问题 1. Say you have an array for which the ith element is...

## Best Time to Buy and Sell Stock

Best Time to Buy and Sell Stock Say you have an array for which the ith element is the price of a g...

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

Say you have an array for which the ith element is the price of a given stock on day i. If you we...
• 2017-07-08 15:16
• 53

## Best Time to Buy and Sell Stock

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

## Best Time to Buy and Sell Stock

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

## LeetCode Best Time to Buy and Sell Stock III && Best Time to Buy and Sell Stock IV

LeetCode这个买股票题，个人认为是出的比较好的，一共四个问题，其中3和4都是hard，在我看来，4的难度比3还是难了不少，因为他涉及到了dp的优化 这里就稍微再提一下第一问和第二问，第一问已经...

举报原因： 您举报文章：深度学习：神经网络中的前向传播和反向传播算法推导 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)