public class Solution {
/**
* 计算你能获得的最大收益
*
* @param prices Prices[i]即第i天的股价
* @return 整型
*/
public int calculateMax(int[] prices) {
int max=0;
for(int i=1;i<prices.length;i++)
{
int left=getDis(prices, 0, i);
int right=getDis(prices,i+1,prices.length-1);
if(left+right>max)
{
max=left+right;
}
}
return max;
}
public int getDis(int[] A, int s,int n) {
if(s>n)
{
return 0;
}
int max=0;
int min=A[s];
for(int i=s;i<=n;i++)
{
if(max<A[i]-min)
{
max=A[i]-min;
}
if(min>A[i])
{
min=A[i];
}
}
return max;
}
}
中国牛市
最新推荐文章于 2020-10-02 22:05:59 发布