publicstaticint getmax(int [] prices ,int start ,int end )
{
int max = 0;
int min = prices[start];
for(int i=start+1;i<=end;i++)
{
if (prices[i]-min>max)
max = prices[i]-min;
if (prices[i]<min)
min = prices[i];
}
return max ;
}
/**
* 计算你能获得的最大收益
*
* @param prices Prices[i]即第i天的股价
* @return 整型
*/
public static int calculateMax(int[] prices)
{
int sum = 0;
for(int i=1;i<prices.length;i++)
{
int temp = getmax(prices,0,i)+getmax(prices,i,prices.length-1);
if(temp>sum)
sum = temp;
}
return sum;
}
风口之下,猪都能飞。当今中国股市牛市,真可谓“错过等七年”。 给你一个回顾历史的机会,已知一支股票连续n天的价格走势,以长度为n的整数数组表示,数组中第i个元素(prices[i])代表该股票第i天的
最新推荐文章于 2018-12-29 17:47:48 发布