Algorithm 04 | code kata

SammyJung·2021년 4월 23일
0
post-thumbnail

풀이

const maxProfit = prices => {

  let arr = [];
  for (let i = 0; i < prices.length; i++) {
    for (let j = i+1; j < prices.length; j++) {
      arr.push(prices[j] - prices[i]);
    } 
  }
  const Max = Math.max(...arr)
  if (Max > 0) {
    return Max
  } else {
    return 0
  }
};
profile
안녕하세요! 프론트엔드 개발자 새미입니다:D

0개의 댓글