Best Time to Buy and Sell Stock

 https://leetcode.com/problems/best-time-to-buy-and-sell-stock/

class Solution {
public:
    int maxProfit(vector<int>& arr) {
    int maxprof=0;
    int minimum=INT_MAX;
    for(int i=0;i<arr.size();i++)
    {
        minimum=min(minimum,arr[i]);
        maxprof=max(maxprof,arr[i]-minimum);
        
    }
         return maxprof;
    }
};

Comments

Popular posts from this blog

Perfect Peak of Array

Is Rectangle?

Sort array with squares!