목록array (3)
에러 안나게 해주세요
var maxProfit = function(prices) { var min = Number.MAX_SAFE_INTEGER; var max = 0; for(let i = 0; i < prices.length; i+=1){ min = Math.min(min, prices[i]); // console.log('최소값',min); max = Math.max(max, prices[i] - min); // console.log('최댓값',max); } return max; }; 저번 주는 포스팅을 안해서 반성 중.. 좀 더 사고를 길러야할 듯 2번 케이스에서 막혀서 한참 고민하다 답을 봄.
var minCostClimbingStairs = function(cost) { if(cost.length === 0) return 0; if(cost.length === 2) return Math.min(cost[0], cost[1]); let First = cost[1]; let Two = cost[0]; for(let i = 2; i < cost.length; i++){ const current = cost[i] + Math.min(First,Two); Two = First; First = current; } return Math.min(First,Two); }; DP 문제 이전 포스팅 문제보다 먼저 풀었는데, 엊그제 해놓고 포스팅을 안했다. 하는 김에 SUBMIT도 같이.. 2시간 동안 DP의 대..
var maxSubArray = function(nums) { if(nums.length == 1) return nums[0]; let num = 0; let FirstNode = nums[0]; let SecondNode = nums[1]; for(let i = 2; i < nums.length; i++){ const current = Math.max(FirstNode,SecondNode); SecondNode=nums[i]; FirstNode=current; if(SecondNode < FirstNode && SecondNode !== FirstNode){ if(num < SecondNode ){ num = SecondNode; console.log(num); } } } return FirstNode..