[Algorithm] 21 week(6.6 ~ 6.12) 2/3

Dev_min·2022년 6월 8일
0

algorithm

목록 보기
69/157

121. Best Time to Buy and Sell Stock

var maxProfit = function(prices) {
    let min = prices[0];
    let result = 0;
    for(let i = 1; i < prices.length; i++){
        if(prices[i] <= min){
            min = prices[i];
        }
        
        result = Math.max(result, prices[i] - min);
  
    }
    
    return result;
};
profile
TIL record

0개의 댓글