首页 > 其他 > 详细

题目2:买卖股票的最佳时机

时间:2017-03-07 23:04:13      阅读:267      评论:0      收藏:0      [点我收藏+]

#include "stdafx.h"
#include<iostream>
using namespace std;
#include<vector>


int maxProfit(vector<int> & prices)
{


int n = prices.size();
if (n <= 1)
return 0;
int max =0;
for (int i = 1,min=prices[0];i < n ;i++) {
int Dvalue=prices[i] - min;
if ( Dvalue > max)
max = Dvalue;
if (prices[i] < min)
min = prices[i];
}
return max;

}

void main()
{
vector<int>prices;
int B[]={3,2,3,1,2,12 };
for(int i=0;i<6;i++)
{
prices.push_back(B[i]);
}

int p=maxProfit(prices);
cout<<p;

}

题目2:买卖股票的最佳时机

原文:http://www.cnblogs.com/123zzq/p/6517150.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!