Best Time to Buy and Sell Stock
生活随笔
收集整理的这篇文章主要介绍了
Best Time to Buy and Sell Stock
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
class Solution {
public:int maxProfit(vector<int>& prices) {
//eg: 5 6 2 3 1 4;
// 记录i之前最小的元素;int min = INT_MAX;int pro = 0;int n=prices.size();for(int i=0;i<n;i++){if(prices[i]-min >pro) pro=prices[i]-min;else if(prices[i] < min) min = prices[i];}return pro;}
};
转载于:https://www.cnblogs.com/julie-yang/p/4671485.html
总结
以上是生活随笔为你收集整理的Best Time to Buy and Sell Stock的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 抽奖自定义中奖概率总结
- 下一篇: 身为java程序员你需要知道的网站(包含