标签:ice for code diff vector fit write 定义 param
class Solution {
public:
/**
* @param prices: Given an integer array
* @return: Maximum profit
*/
int maxProfit(vector<int> &prices) {
// write your code here
if(prices.empty())
return 0 ;
int max = 0; /* 定义最大利润 */
int min = prices[0];
for(int i = 1 ; i < prices.size() ; i++ )
{
if(prices[i] < min)
min = prices[i];
int differ = prices[i] - min ;
if(differ > max)
max = differ;
}
return max;
}
};
标签:ice for code diff vector fit write 定义 param
原文地址:http://www.cnblogs.com/zhaoshengyun/p/6522813.html