121. Best Time to Buy and Sell Stock

来源:互联网 发布:iphone闪存检测软件 编辑:程序博客网 时间:2024/06/03 12:50
class Solution {public:int maxProfit(vector<int>& prices) {int len = prices.size();if (len == 0){return 0;}int minpos = 0;int maxn = 0 ;int j = 0;for (int i = 0; i < len; i++){if (prices[minpos] > prices[i]){minpos = i;}if (maxn < prices[i] - prices[minpos]){maxn = prices[i] - prices[minpos];}}return maxn;}};

原创粉丝点击