1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
#include<iostream> #include<vector> #include<cmath> using namespace std; class Solution { public: int maxProfit(vector<int>& prices) { int ans=0; for(int i=0;i<prices.size();i++) { int m=prices[i]; for(int j=i+1;j<prices.size();j++) { if(prices[j]>m) { ans=max(prices[j]-m,ans); } } } return ans; } }; int main() { vector<int>a={7,6,4,3,1}; cout<<Solution().maxProfit(a)<<endl; return 0; }
|
近期评论