Posted on

Description

Submission

class Solution {
public:
    int maximumDifference(vector<int>& nums) {
        int minElement = INT_MAX;
        int ret = -1;

        for(int x: nums) {
            if(minElement < x)
            ret = max(ret, x - minElement);
            minElement = min(x, minElement);
        }

        return ret;
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *