Advertisement
nikunjsoni

121

Jun 17th, 2021
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.30 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     int maxProfit(vector<int>& prices) {
  4.         int low=prices[0], ans=0;
  5.         for(int i=1; i<prices.size(); i++)
  6.             if(prices[i] < low)
  7.                 low = prices[i];
  8.             else
  9.                 ans = max(ans, prices[i]-low);
  10.         return ans;
  11.     }
  12. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement