89ms Javascript solution...... JS is much faster than Java


  • 4
    B
    var maxProfit = function(prices) {
        var len = prices.length;
        if(len <= 1) return 0;
        var ret = 0;
        for(var i = 1; i < len; i++) {
            ret += Math.max(0, prices[i] - prices[i-1]);
        }
        return ret;
    };

  • -1
    G

    Unfortunately, it's not C.

    Praise it.


Log in to reply
 

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