Your runtime beats 99.05% of javascript submissions


  • 0
    K
    var maxProfit = function(prices) {
      var len = prices.length;
      var curr = prices[0];
      var res = 0;
      
      for (var i=0; i< prices.length; i++){
        if (prices[i] > curr && (prices[i]-curr > res) ){
          res = prices[i] - curr;
        }
        if (prices[i] < curr){
          curr = prices[i];
        }
      }
      
      return res;
    };

Log in to reply
 

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