标签:max cto turn price pre bsp 股票 solution int
1 class Solution 2 { 3 public: 4 int maxProfit(vector<int>& prices) 5 { 6 if(prices.empty()) return 0; 7 int n = prices.size(); 8 int buy = prices[0]; 9 int res = 0; 10 for(int i = 1;i < n;i ++) 11 { 12 res = max(res,prices[i] - buy); 13 if(buy > prices[i]) buy = prices[i]; 14 } 15 return res; 16 } 17 };
标签:max cto turn price pre bsp 股票 solution int
原文地址:https://www.cnblogs.com/yuhong1103/p/12614540.html