Javascript solution, if anyone is interested


  • 7
    P
    var maxProfit = function(prices) {
        var min = Number.MAX_SAFE_INTEGER; 
        var max = 0;
        for (var i = 0; i < prices.length; i++) {
            min = Math.min(min, prices[i]);
            max = Math.max(max, prices[i] - min);
        }
        return max;
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.