Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int maxProfit(vector<int>& prices) {
- int low=prices[0], ans=0;
- for(int i=1; i<prices.size(); i++)
- if(prices[i] < low)
- low = prices[i];
- else
- ans = max(ans, prices[i]-low);
- return ans;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement