题目:
解答:
1 class Solution { 2 public: 3 int maxProfit(vector<int>& prices) 4 { 5 int cost = INT_MAX; 6 int profit = 0; 7 for (int price: prices) 8 { 9 cost = std::min(cost, price); 10 profit = std::max(profit, price - cost); 11 } 12 13 return profit; 14 15 } 16 };
原文:https://www.cnblogs.com/ocpc/p/12859851.html