knakul853

Untitled

Jul 15th, 2020
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.35 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     int maxProfit(vector<int>& prices) {
  4.       int l = prices.size();
  5.       int pro=0;
  6.       int minp=INT_MAX;
  7.       for(int i=0;i<l;i++)
  8.       {
  9.         if(prices[i]<minp)minp=prices[i];
  10.         else if(prices[i]-minp>pro)
  11.         {
  12.           pro = prices[i]-minp;
  13.         }
  14.        
  15.     }
  16.       return pro;
  17.     }
  18. };
Add Comment
Please, Sign In to add comment